function _drush_core_rsync_both_remote

master rsync.core.inc _drush_core_rsync_both_remote($source, $destination, $additional_options, $source_path)

Handle an rsync operation from a remote site to a remote site by first rsync'ing to a local location, and then copying that location to its final destination.

1 call to _drush_core_rsync_both_remote()
drush_core_rsync in commands/core/rsync.core.inc
A command callback.

File

commands/core/rsync.core.inc, line 228

Code

function _drush_core_rsync_both_remote($source, $destination, $additional_options, $source_path) {
  $options = $additional_options + drush_redispatch_get_options();

  // Make a temporary directory to copy to.  There are three
  // cases to consider:
  //
  // 1. rsync @src:file.txt @dest:location
  // 2. rsync @src:dir @dest:location
  // 3. rsync @src:dir/ @dest:location
  //
  // We will explain each of these in turn.
  //
  // 1. Copy a single file.  We'll split this up like so:
  //
  //    rsync @src:file.txt /tmp/tmpdir
  //    rsync /tmp/tmpdir/file.txt @dest:location
  //
  // Since /tmp/tmpdir is empty, we could also rsync from
  // '/tmp/tmpdir/' if we wished.
  //
  // 2. Copy a directory. A directory with the same name
  // is copied to the destination.  We'll split this up like so:
  //
  //    rsync @src:dir /tmp/tmpdir
  //    rsync /tmp/tmpdir/dir @dest:location
  //
  // The result is that everything in 'dir' is copied to @dest,
  // and ends up in 'location/dir'.
  //
  // 3. Copy the contents of a directory.  We will split this
  // up as follows:
  //
  //    rsync @src:dir/ /tmp/tmpdir
  //    rsync /tmp/tmpdir/ @dest:location
  //
  // After the first rsync, everything in 'dir' will end up in
  // tmpdir.  The second rsync copies everything in tmpdir to
  // @dest:location without creating an encapsulating folder
  // in the destination (i.e. there is no 'tmpdir' in the destination).
  //
  // All three of these cases need to be handled correctly in order
  // to ensure the correct results.  In all cases the first
  // rsync always copies to $tmpDir, however the second rsync has
  // two cases that depend on the source path.  If the source path ends
  // in /, the contents of a directory have been copied to $tmpDir, and
  // the contents of $tmpDir must be copied to the destination.  Otherwise,
  // a specific file or directory has been copied to $tmpDir and that
  // specific item, identified by basename($source_path) must be copied to
  // the destination.

  $putInTmpPath = drush_tempdir();
  $getFromTmpPath = "$putInTmpPath/";
  if (substr($source_path, -1) !== '/') {
    $getFromTmpPath .= basename($source_path);
  }

  // Copy from the source to the temporary location. Exit on failure.
  $values = drush_invoke_process('@self', 'core-rsync', array($source, $putInTmpPath), $options);
  if ($values['error'] != 0) {
    return FALSE;
  }

  // Copy from the temporary location to the final destination.
  $values = drush_invoke_process('@self', 'core-rsync', array($getFromTmpPath, $destination), $options);

  return $values['error'] == 0;
}