ignoreDotFiles() публичный Метод

Excludes "hidden" directories and files (starting with a dot).
См. также: ExcludeDirectoryFilterIterator
public ignoreDotFiles ( boolean $ignoreDotFiles ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$ignoreDotFiles boolean Whether to exclude "hidden" files or not
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance
 /**
  * @return Finder
  */
 protected function getSpool()
 {
     $filesystem = new Filesystem();
     $finder = new Finder();
     if ($filesystem->exists($this->spoolDir)) {
         $spool = $finder->ignoreDotFiles(true)->in($this->spoolDir)->files();
         return $spool;
     }
     throw new \RuntimeException("Spool not found or empty: " . $this->spoolDir);
 }
Пример #2
0
 /**
  *
  * @param string $path        	
  * @return \Symfony\Component\Finder\Finder
  */
 protected function getFinder($path)
 {
     $finder = new Finder();
     $finder->ignoreDotFiles(TRUE);
     $finder->depth(0);
     $finder->exclude($this->excludeDirs);
     if (!is_dir($path)) {
         return $finder;
     }
     $finder->in($path);
     return $finder;
 }
Пример #3
0
 public function testClear()
 {
     file_put_contents($this->app['config']['root_dir'] . '/app/cache/.dummykeep', 'test');
     // 'doctrine', 'profiler', 'twig' ディレクトリを削除
     Cache::clear($this->app, false);
     $finder = new Finder();
     $iterator = $finder->ignoreDotFiles(false)->in($this->app['config']['root_dir'] . '/app/cache')->files();
     foreach ($iterator as $fileinfo) {
         $this->assertStringEndsWith('keep', $fileinfo->getPathname(), 'keep しか存在しないはず');
     }
     $this->assertTrue($this->root->hasChild('app/cache/.gitkeep'), '.gitkeep は存在するはず');
     $this->assertTrue($this->root->hasChild('app/cache/.dummykeep'), '.dummykeep は存在するはず');
 }
 /**
  * Returns a Finder instance for the files that will be included in the
  * backup.
  *
  * By default we ignore unreadable files and directories as well as, common
  * version control folders / files, "Dot" files and anything matching the
  * exclude rules.
  *
  * @uses Finder
  * @return Finder The Finder iterator of all files to be included
  */
 public function get_files()
 {
     $finder = new Finder();
     $finder->followLinks(true);
     $finder->ignoreDotFiles(false);
     $finder->ignoreVCS(true);
     $finder->ignoreUnreadableDirs(true);
     // Skip unreadable files too
     $finder->filter(function (\SplFileInfo $file) {
         if (!$file->isReadable()) {
             return false;
         }
     });
     // Finder expects exclude rules to be in a regex format
     $exclude_rules = $this->excludes->get_excludes_for_regex();
     // Skips folders/files that match default exclude patterns
     foreach ($exclude_rules as $exclude) {
         $finder->notPath($exclude);
     }
     return $finder->in(Path::get_root());
 }
 /**
  * @param OutputInterface $output
  * @return void
  */
 protected function cleanCustom(OutputInterface $output)
 {
     if (empty($this->options['custom'])) {
         return;
     }
     foreach ($this->options['custom'] as $options) {
         try {
             $finder = new Finder();
             $finder->ignoreDotFiles(false);
             $finder->ignoreVCS(false);
             $finder->ignoreUnreadableDirs(true);
             $in = [];
             if (!is_array($options['in'])) {
                 $options['in'] = [$options['in']];
             }
             foreach ($options['in'] as $dir) {
                 $in[] = $this->baseDir . $dir;
             }
             $finder->in($in);
             if (!empty($options['type'])) {
                 switch ($options['type']) {
                     case 'files':
                         $finder->files();
                         break;
                     case 'dirs':
                     case 'directories':
                         $finder->directories();
                         break;
                 }
             }
             if (!empty($options['notName'])) {
                 if (!is_array($options['notName'])) {
                     $options['notName'] = [$options['notName']];
                 }
                 foreach ($options['notName'] as $notName) {
                     $finder->notName($notName);
                 }
             }
             if (!empty($options['name'])) {
                 if (!is_array($options['name'])) {
                     $options['name'] = [$options['name']];
                 }
                 foreach ($options['name'] as $notName) {
                     $finder->name($notName);
                 }
             }
             if (!empty($options['depth'])) {
                 $finder->depth($options['depth']);
             }
             foreach ($finder as $file) {
                 $this->files[] = $file->getRealPath();
             }
         } catch (\Exception $e) {
             // ignore errors
         }
     }
 }
Пример #6
0
 public function testIgnoreDotFiles()
 {
     $finder = new Finder();
     $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
     $this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
     $finder = new Finder();
     $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
     $this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
     $finder = new Finder();
     $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
     $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
 }
Пример #7
0
 /**
  * Recursively scans a directory to calculate the total filesize
  *
  * Locks should be set by the caller with `set_transient( 'hmbkp_directory_filesizes_running', true, HOUR_IN_SECONDS );`
  *
  * @return array $directory_sizes    An array of directory paths => filesize sum of all files in directory
  */
 public function recursive_filesize_scanner()
 {
     /**
      * Raise the `memory_limit` and `max_execution time`
      *
      * Respects the WP_MAX_MEMORY_LIMIT Constant and the `admin_memory_limit`
      * filter.
      */
     @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
     @set_time_limit(0);
     // Use the cached array directory sizes if available
     $directory_sizes = $this->get_cached_filesizes();
     // If we do have it in cache then let's use it and also clear the lock
     if (is_array($directory_sizes)) {
         delete_transient('hmbkp_directory_filesizes_running');
         return $directory_sizes;
     }
     // If we don't have it cached then we'll need to re-calculate
     $finder = new Finder();
     $finder->followLinks();
     $finder->ignoreDotFiles(false);
     $finder->ignoreUnreadableDirs(true);
     $files = $finder->in(Path::get_root());
     foreach ($files as $file) {
         if ($file->isReadable()) {
             $directory_sizes[wp_normalize_path($file->getRealpath())] = $file->getSize();
         } else {
             $directory_sizes[wp_normalize_path($file->getRealpath())] = 0;
         }
     }
     file_put_contents(PATH::get_path() . '/.files', gzcompress(json_encode($directory_sizes)));
     // Remove the lock
     delete_transient('hmbkp_directory_filesizes_running');
     return $directory_sizes;
 }
 /**
  * LegacyRouteLoader constructor.
  *
  * @param string $legacyPath
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($legacyPath, Finder $finder = null)
 {
     $this->finder = $finder ?: new Finder();
     $this->finder->ignoreDotFiles(true)->files()->name('*.php')->in($legacyPath);
 }
Пример #9
0
 /**
  *
  * @return Finder
  */
 protected function getFinder()
 {
     if (null === $this->finder) {
         $finder = new Finder();
         $settings = $this->getSettings();
         foreach ($settings->getSrc() as $source) {
             if (is_dir($source)) {
                 $finder->in($source);
             }
             if (is_file($source)) {
                 $finder->append(array($source));
             }
         }
         if (true === $settings->getFollowLinks()) {
             $finder->followLinks();
         }
         $finder->ignoreDotFiles($settings->getIgnoreDotFiles());
         $finder->name($settings->getFileSuffix());
         $finder->exclude($settings->getExclude());
         if (NULL !== $settings->getDate()) {
             $finder->date($settings->getDate());
         }
         $this->setFinder($finder);
     }
     return $this->finder;
 }
Пример #10
0
 /**
  * @param bool $includeDotFiles
  * @return $this
  */
 public function includeDotFiles($includeDotFiles = true)
 {
     $this->finder->ignoreDotFiles(!$includeDotFiles);
     return $this;
 }
Пример #11
0
 /**
  * Load all files from the extension.
  */
 private function loadFiles()
 {
     $finder = new Finder();
     $iterator = $finder->ignoreDotFiles(false)->files()->sortByName()->ignoreVCS(true)->exclude('vendor')->exclude('tests')->exclude('travis')->in($this->directory);
     $loader = new FileLoader($this->output, $this->debug, $this->basedir, $this->directory);
     foreach ($iterator as $file) {
         /** @var \Symfony\Component\Finder\SplFileInfo $file */
         if (!$file->getRealPath()) {
             $this->output->write("<info>Finder found a file, but it does not seem to be readable or does not actually exist.</info>");
             continue;
         }
         $loadedFile = $loader->loadFile($file->getRealPath());
         if ($loadedFile != null) {
             $this->files[] = $loadedFile;
             $this->dirList[] = $file->getRealPath();
         } else {
             $this->output->addMessage(Output::FATAL, "Unable to load file: " . $file->getRealPath());
         }
     }
 }
Пример #12
0
 /**
  * @param DirectoryPath $relativeDirectoryPath
  *
  * @return DirectoryListing
  */
 public function listDirectory(DirectoryPath $relativeDirectoryPath)
 {
     $repositoryPath = $this->gitRepository->getRepositoryPath();
     /* @var PageFile[] $pages */
     $pages = array();
     /* @var Directory[] $subDirectories */
     $subDirectories = array();
     /* @var \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File[] $otherFiles */
     $otherFiles = array();
     $finder = new Finder();
     $finder->in($this->gitRepository->getAbsolutePathString($relativeDirectoryPath));
     $finder->depth(0);
     foreach ($finder->files() as $file) {
         /* @var \Symfony\Component\Finder\SplFileInfo $file */
         if ($file->getExtension() == "md") {
             $pages[] = $this->createPageFile($repositoryPath, $relativeDirectoryPath, $file);
         } else {
             if ($file->getExtension() != 'lock') {
                 $otherFile = new \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File($repositoryPath->toAbsoluteFileString(), $relativeDirectoryPath->toRelativeFileString(), $file->getRelativePathName());
                 $otherFiles[] = $otherFile;
             }
         }
     }
     $finder = new Finder();
     $finder->in($this->gitRepository->getAbsolutePathString($relativeDirectoryPath));
     $finder->depth(0);
     $finder->ignoreDotFiles(true);
     foreach ($finder->directories() as $directory) {
         /* @var \Symfony\Component\Finder\SplFileInfo $directory */
         $subDirectory = new Directory($repositoryPath->toAbsoluteFileString(), $relativeDirectoryPath->toRelativeFileString(), $directory->getRelativePathName() . DIRECTORY_SEPARATOR);
         $subDirectories[] = $subDirectory;
     }
     usort($pages, function (PageFile $a, PageFile $b) {
         return strcmp($a->getTitle(), $b->getTitle());
     });
     usort($subDirectories, function (Directory $a, Directory $b) {
         return strcmp($a->getFilename(), $b->getFilename());
     });
     usort($otherFiles, function (\Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File $a, \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File $b) {
         return strcmp($a->getFilename(), $b->getFilename());
     });
     return new DirectoryListing($relativeDirectoryPath, $pages, $subDirectories, $otherFiles);
 }
Пример #13
0
 private function scanFolders($path, $parent)
 {
     $finder = new Finder();
     $finder->in($path);
     $finder->directories();
     $finder->ignoreDotFiles(true);
     $finder->depth(0);
     $finder->sortByName();
     foreach ($finder as $entity) {
         /* @var $entity SplFileInfo */
         $name = $entity->getFilename();
         // Skip items starting with underscore
         if (preg_match('~^_~', $name)) {
             continue;
         }
         // Skip items starting with dot
         if (preg_match('~^\\.~', $name)) {
             continue;
         }
         $this->scanFiles($entity->getPathname(), $parent);
     }
 }
Пример #14
0
 /**
  * @return Finder
  */
 public function ignoreDotFiles($ignoreDotFiles)
 {
     return parent::ignoreDotFiles($ignoreDotFiles);
 }
Пример #15
0
 /**
  * Return the single depth list of files and subdirectories in $directory ordered by total filesize
  *
  * Will schedule background threads to recursively calculate the filesize of subdirectories.
  * The total filesize of each directory and subdirectory is cached in a transient for 1 week.
  *
  * @param string $directory The directory to scan
  *
  * @return array returns an array of files ordered by filesize
  */
 public function list_directory_by_total_filesize($directory)
 {
     $files = $files_with_no_size = $empty_files = $files_with_size = $unreadable_files = array();
     if (!is_dir($directory)) {
         return $files;
     }
     $found = array();
     if (!empty($this->files)) {
         return $this->files;
     }
     $default_excludes = $this->backup->default_excludes();
     $finder = new Finder();
     $finder->ignoreDotFiles(false);
     $finder->ignoreUnreadableDirs();
     $finder->followLinks();
     $finder->depth('== 0');
     foreach ($default_excludes as $exclude) {
         $finder->notPath($exclude);
     }
     foreach ($finder->in($directory) as $entry) {
         $files[] = $entry;
         // Get the total filesize for each file and directory
         $filesize = $this->filesize($entry);
         if ($filesize) {
             // If there is already a file with exactly the same filesize then let's keep increasing the filesize of this one until we don't have a clash
             while (array_key_exists($filesize, $files_with_size)) {
                 $filesize++;
             }
             $files_with_size[$filesize] = $entry;
         } elseif (0 === $filesize) {
             $empty_files[] = $entry;
         } else {
             $files_with_no_size[] = $entry;
         }
     }
     // Add 0 byte files / directories to the bottom
     $files = $files_with_size + array_merge($empty_files, $unreadable_files);
     // Add directories that are still calculating to the top
     if ($files_with_no_size) {
         // We have to loop as merging or concatenating the array would re-flow the keys which we don't want because the filesize is stored in the key
         foreach ($files_with_no_size as $entry) {
             array_unshift($files, $entry);
         }
     }
     return $files;
 }
Пример #16
0
 /**
  * Finds directories in a given path
  *
  * @param     $directory
  * @param     $fileType
  * @param int $depth
  * @return Finder
  */
 private function findFiles($directory, $fileType, $depth = 0)
 {
     $finder = new Finder();
     $finder->ignoreDotFiles(true)->ignoreUnreadableDirs()->in($directory)->name($fileType)->depth($depth)->sortByName();
     return $finder->count() > 0 ? $finder : false;
 }
Пример #17
0
 /**
  * Return an array of all files in the filesystem.
  *
  * @param bool $ignore_default_exclude_rules If true then will return all files under root. Otherwise returns all files except those matching default exclude rules.
  *
  * @return array
  */
 public function get_files($ignore_default_exclude_rules = false)
 {
     $found = array();
     if (!empty($this->files)) {
         return $this->files;
     }
     $finder = new Finder();
     $finder->followLinks();
     $finder->ignoreDotFiles(false);
     $finder->ignoreUnreadableDirs();
     if (!$ignore_default_exclude_rules) {
         // Skips folders/files that match default exclude patterns
         foreach ($this->default_excludes() as $exclude) {
             $finder->notPath($exclude);
         }
     }
     foreach ($finder->in($this->get_root()) as $entry) {
         $this->files[] = $entry;
     }
     return $this->files;
 }
Пример #18
0
 /**
  * Return an array of all files in the filesystem
  *
  * @return \RecursiveIteratorIterator
  */
 public function get_files()
 {
     $found = array();
     if (!empty($this->files)) {
         return $this->files;
     }
     $finder = new Finder();
     $finder->followLinks();
     $finder->ignoreDotFiles(false);
     $finder->ignoreUnreadableDirs();
     foreach ($this->default_excludes() as $exclude) {
         $finder->notPath($exclude);
     }
     foreach ($finder->in($this->get_root()) as $entry) {
         $this->files[] = $entry;
     }
     return $this->files;
 }
Пример #19
0
 /**
  * Create the zip archive
  *
  * @param array $data Extension data
  *
  * @return string
  */
 public function create_zip($data)
 {
     $zip_path = $this->root_path . 'store/tmp-ext/' . "{$data['extension']['vendor_name']}_{$data['extension']['extension_name']}-{$data['extension']['extension_version']}.zip";
     $ext_path = $this->root_path . 'store/tmp-ext/' . "{$data['extension']['vendor_name']}/{$data['extension']['extension_name']}/";
     $zip_archive = new \ZipArchive();
     $zip_archive->open($zip_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
     $finder = new Finder();
     $finder->ignoreDotFiles(false)->ignoreVCS(false)->files()->in($ext_path);
     foreach ($finder as $file) {
         $zip_archive->addFile($file->getRealPath(), "{$data['extension']['vendor_name']}/{$data['extension']['extension_name']}/" . $file->getRelativePath() . '/' . $file->getFilename());
     }
     $zip_archive->close();
     return $zip_path;
 }
Пример #20
0
 /**
  * @param string $logDir
  *
  * @throws \InvalidArgumentException
  *
  * @return Finder
  */
 private function getDirFiles($logDir)
 {
     $finder = new Finder();
     $finder->ignoreDotFiles(true)->ignoreVCS(true);
     $finder->files()->in($logDir)->name('*.log');
     return $finder;
 }
 /**
  * Returns a list of files in the directory
  *
  * @param	string	$dir	Directory to go through
  * @return	array	List of files
  */
 protected function getFileList($dir)
 {
     $finder = new Finder();
     $iterator = $finder->ignoreDotFiles(false)->files()->sortByName()->in($dir);
     $files = array();
     foreach ($iterator as $file) {
         /** @var \SplFileInfo $file */
         $files[] = str_replace(DIRECTORY_SEPARATOR, '/', substr($file->getPathname(), strlen($dir) + 1));
     }
     return $files;
 }