You are here

protected function FilePermissions::getFileList in Security Review 8

Scans a directory recursively and returns the files and directories inside.

Parameters

string $directory: The directory to scan.

string[] $parsed: Array of already parsed real paths.

string[] $ignore: Array of file names to ignore.

Return value

string[] The items found.

1 call to FilePermissions::getFileList()
FilePermissions::run in src/Checks/FilePermissions.php
The actual procedure of carrying out the check.

File

src/Checks/FilePermissions.php, line 183

Class

FilePermissions
Check that files aren't writeable by the server.

Namespace

Drupal\security_review\Checks

Code

protected function getFileList($directory, array &$parsed = NULL, array &$ignore = NULL) {

  // Initialize $parsed and $ignore arrays.
  if ($parsed === NULL) {
    $parsed = [
      realpath($directory),
    ];
  }
  if ($ignore === NULL) {
    $ignore = $this
      ->getIgnoreList();
  }

  // Start scanning.
  $items = [];
  if ($handle = opendir($directory)) {
    while (($file = readdir($handle)) !== FALSE) {

      // Don't check hidden files or ones we said to ignore.
      $path = $directory . "/" . $file;
      if ($file[0] != "." && !in_array($file, $ignore) && !in_array(realpath($path), $ignore)) {
        if (is_dir($path) && !in_array(realpath($path), $parsed)) {
          $parsed[] = realpath($path);
          $items = array_merge($items, $this
            ->getFileList($path, $parsed, $ignore));
        }
        $items[] = preg_replace("/\\/\\//si", "/", $path);
      }
    }
    closedir($handle);
  }
  return $items;
}