You are here

function _s3fs_copy_file_system_to_s3 in S3 File System 7.2

Same name and namespace in other branches
  1. 7.3 s3fs.module \_s3fs_copy_file_system_to_s3()

Copies all the local files from the specified file system into S3.

2 calls to _s3fs_copy_file_system_to_s3()
drush_s3fs_copy_local in ./s3fs.drush.inc
Copys all files from the local public/private filesystem folders into S3, if s3fs is configured to take over those systems.
_s3fs_copy_local_submit in ./s3fs.admin.inc
Submit callback for the "Copy local files to S3" buttons.

File

./s3fs.module, line 918
Hook implementations and other primary functionality for S3 File System.

Code

function _s3fs_copy_file_system_to_s3($scheme) {
  $config = _s3fs_get_config();
  if ($scheme == 'public') {
    $source_folder = realpath(variable_get('file_public_path', conf_path() . '/files'));
  }
  elseif ($scheme == 'private') {
    $source_folder = variable_get('file_private_path', '');
    $source_folder_real = realpath($source_folder);
    if (empty($source_folder) || empty($source_folder_real)) {
      drupal_set_message('Private file system base path is unknown. Unable to perform S3 copy.', 'error');
      return;
    }
  }
  $file_paths = _s3fs_recursive_dir_scan($source_folder);
  foreach ($file_paths as $path) {
    $relative_path = str_replace($source_folder . '/', '', $path);
    print "Copying {$scheme}://{$relative_path} into S3...\n";

    // Finally get to make use of S3fsStreamWrapper's "S3 is actually a local
    // file system. No really!" functionality.
    copy($path, "{$scheme}://{$relative_path}");
  }
  drupal_set_message(t('Copied all local %scheme files to S3.', array(
    '%scheme' => $scheme,
  )), 'status');
}