You are here

private static function S3fsFileMigrationBatch::isFileAlreadyUploaded in S3 File System 8.3

Same name and namespace in other branches
  1. 4.0.x src/Batch/S3fsFileMigrationBatch.php \Drupal\s3fs\Batch\S3fsFileMigrationBatch::isFileAlreadyUploaded()
1 call to S3fsFileMigrationBatch::isFileAlreadyUploaded()
S3fsFileMigrationBatch::copyOperation in src/Batch/S3fsFileMigrationBatch.php
Batch operation callback that copy files to S3 File System.

File

src/Batch/S3fsFileMigrationBatch.php, line 303

Class

S3fsFileMigrationBatch
Batch migrate files to a S3 bucket.

Namespace

Drupal\s3fs\Batch

Code

private static function isFileAlreadyUploaded($srcPath, $destUri, array $uploadConditions = []) {
  $streamWrapper = \Drupal::service('stream_wrapper.s3fs');
  $srcStat = stat($srcPath);
  $destStat = $streamWrapper
    ->url_stat($destUri, 0);

  // Source has been deleted since batch created.
  if (empty($srcStat)) {
    return TRUE;
  }

  // No conditions or dest doesnt exist.
  if (empty($uploadConditions) || empty($destStat)) {
    return FALSE;
  }
  if (!empty($uploadConditions['newer'])) {
    if ($srcStat['mtime'] > $destStat['mtime']) {
      return FALSE;
    }
  }
  if (!empty($uploadConditions['size'])) {
    if ($srcStat['size'] != $destStat['size']) {
      return FALSE;
    }
  }
  return TRUE;
}