You are here

public function S3fsFileMigrationBatch::dirScan in S3 File System 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Batch/S3fsFileMigrationBatch.php \Drupal\s3fs\Batch\S3fsFileMigrationBatch::dirScan()

Scans a given directory.

Parameters

string $dir: The directory to be scanned.

Return value

array Array of file paths.

Overrides S3fsFileMigrationBatchInterface::dirScan

1 call to S3fsFileMigrationBatch::dirScan()
S3fsFileMigrationBatch::execute in src/Batch/S3fsFileMigrationBatch.php
Copies all the local files from the specified file system into S3.

File

src/Batch/S3fsFileMigrationBatch.php, line 93

Class

S3fsFileMigrationBatch
Batch migrate files to a S3 bucket.

Namespace

Drupal\s3fs\Batch

Code

public function dirScan($dir) {
  $output = [];
  $files = scandir($dir);
  foreach ($files as $file) {
    $path = "{$dir}/{$file}";
    if ($file != '.' && $file != '..') {

      // In case they put their private root folder inside their public one,
      // skip it. When listing the private file system contents, $path will
      // never trigger this.
      if ($path == realpath(PrivateStream::basePath() ? PrivateStream::basePath() : '')) {
        continue;
      }
      if (is_dir($path)) {
        $output = array_merge($output, $this
          ->dirScan($path));
      }
      else {
        $output[] = $path;
      }
    }
  }
  return $output;
}