Example #1
0
 /**
  * @param FileNodeCollectionInterface $files
  *
  * @return CollectionInterface
  */
 public function findFiles(FileNodeCollectionInterface $files)
 {
     return $files->filter(function (FileNode $file) {
         $metadata = $file->getMetadata();
         if ($metadata) {
             return $this->filter->matches($file->getMetadata());
         } else {
             return false;
         }
     });
 }
Example #2
0
 /**
  * @param FileNodeCollectionInterface $files
  * @param FileNodeInterface           $target
  * @param string                      $cmd
  * @param bool                        $keepOld
  *
  * @return FileNodeInterface
  * @throws \Graze\DataFile\Modify\Exception\MakeDirectoryFailedException
  */
 private function runCommand(FileNodeCollectionInterface $files, FileNodeInterface $target, $cmd, $keepOld = true)
 {
     if ($target instanceof FileNode) {
         $maker = new MakeDirectory();
         $maker->makeDirectory($target);
     }
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new ProcessFailedException($process);
     }
     if (!$keepOld) {
         $this->log(LogLevel::DEBUG, "Deleting old files in collection {$files}");
         $files->map(function (LocalFile $item) {
             if ($item->exists()) {
                 $item->delete();
             }
             $count = iterator_count(new DirectoryIterator($item->getDirectory()));
             if ($count == 2) {
                 rmdir($item->getDirectory());
             }
         });
     }
     return $target;
 }