Call rsync on a Pantheon site

@command remote:rsync
@aliases rsync

@param string $src Source path
@param string $dest Destination path
@param array $rsyncOptions All of the options after -- (passed to rsync)
775685
public function rsyncCommand($src, $dest, array $rsyncOptions)
    {
        if (strpos($src, ':') !== false) {
            $site_env_id = $this->getSiteEnvIdFromPath($src);
            $src = $this->removeSiteEnvIdFromPath($src);
        } else {
            $site_env_id = $this->getSiteEnvIdFromPath($dest);
            $dest = $this->removeSiteEnvIdFromPath($dest);
        }

        return $this->rsync($site_env_id, $src, $dest, $rsyncOptions);
    }
352712
public function copy( Table $src, Table $dest ) {

		$this->copy_structure( $src, $dest );
		$src_table  = $this->database->quote_identifier( $src->name() );
		$dest_table = $this->database->quote_identifier( $dest->name() );
		$query      = "INSERT INTO {$dest_table} SELECT * FROM {$src_table}";

		return (bool) $this->database->query( $query );
	}
309323
private static function copy($src, $dest)
  {
    // If the destination directory does not exist create it
    if(!is_dir($dest)) {
      if(!mkdir($dest,0777,true)) {
        // If the destination directory could not be created stop processing
        echo "Can't create destination path: {$dest}\n";
        return false;
      }
    }
    copy($src, "$dest/" . basename($src));
  }
1163105
public static function copyTo(StreamInterface $src, $dest)
    {
        $destStream = $dest instanceof StreamInterface ? $dest : new Stream($dest, Stream::MODE_READ_WRITE_RESET);

        static::copy($src, $destStream);

        $destStream->close();
    }
596805
public static function symlink($src, $dst)
    {
        try {
            // remove old link
            if (is_link($dst) && readlink($dst) !== $src) {
                unlink($dst);
            }

            if (!is_link($dst)) {

                return symlink($src, $dst);
            }
        } catch (\Exception $e) {
            if (posix_isatty(0)) {
                passthru("sudo ln -s $src $dst", $retval);

                return $retval === 0;
            }
        }
    }
1053526
protected function mergeOptions($src, $dst, &$options) {
    if (!isset($options['width']) && !isset($options['height'])) {
      $info = $this->getVideoInfo($src);
      $options['width'] = $info['width'];
      $options['height'] = $info['height'];
      if (!$info['audioStreams']) {
        $options['audio'] = false;
      }
    }
    if (!isset($options['targetFormat'])) {
      $ext = strtolower(substr($dst, strrpos($dst, '.') + 1));
      $options['targetFormat'] = $ext;
    }
  }
1244600
def copytree(src, dst):
    
    from os import path, waitpid
    from subprocess import Popen, PIPE

    #Append any trailing / that we need to get rsync to work correctly.
    source = path.join(src, "")
    desti = path.join(dst, "")
    if not path.isdir(desti):
        from os import mkdir
        mkdir(desti)
    
    prsync = Popen("rsync -t -u -r {} {}".format(source, desti), close_fds=True,
                    shell=True, executable="/bin/bash", stdout=PIPE, stderr=PIPE)
    waitpid(prsync.pid, 0)
    #Redirect the output and errors so that we don't pollute stdout.
    #output = prsync.stdout.readlines()
    error = prsync.stderr.readlines()
    prsync.stderr.close()
    prsync.stdout.close()

    if len(error) > 0:
        from fortpy.msg import warn
        warn("Error while copying {} using rsync.\n\n{}".format(source, '\n'.join(error)))
97323
public function copy(PhingFile $src, PhingFile $dest)
    {
        global $php_errormsg;

        if (!$src->isLink()) {
            parent::copy($src, $dest);
            return;
        }

        $srcPath = $src->getAbsolutePath();
        $destPath = $dest->getAbsolutePath();

        $linkTarget = $src->getLinkTarget();
        if (false === @symlink($linkTarget, $destPath)) {
            $msg = "FileSystem::copy() FAILED. Cannot create symlink from $destPath to $linkTarget.";
            throw new Exception($msg);
        }
    }
114910
public function docs($dest = null)
    {
        if (!$dest) {
            $dest = __DIR__ . '/../peridot-php.github.io';
        }
        $src = __DIR__ . '/docs';
        $this->taskDeleteDir([
            $dest . '/docs',
            $src
        ])->run();
        $this->taskExec('apigen generate')->run();
        $this->taskCopyDir([
            $src => $dest . '/docs'
        ])->run();
        $this->taskDeleteDir([$src])->run();
    }
766324
function syncMod(src, dest, mode) {
    if (mode !== false) {
      fs.chmodSync(dest, (mode === true) ? fs.lstatSync(src).mode : mode);
    }
  }
623667
protected function copyFileWithDirsCreating($src, $dest)
    {
        $dirPathOfDestFile = dirname($dest);

        if (! File::exists($dirPathOfDestFile)) {
            File::makeDirectory($dirPathOfDestFile, 0755, true);
        }

        if (! File::exists($dest)) {
            File::copy($src, $dest);
        }
    }
297874
protected function recursiveCopy($src,$dst)
    {
        if($this->isZip($src)) { 
            $this->extractZip($src, $this->getInstallDir());
            return;
        }
        $dir = opendir($src); 
        if(!is_dir($dst)) {
            mkdir($dst);
        }
        while(false !== ( $file = readdir($dir)) ) { 
            if (( $file != '.' ) && ( $file != '..' )) { 
                if ( is_dir($src . '/' . $file) ) { 
                    recursiveCopy($src . '/' . $file,$dst . '/' . $file); 
                } 
                else { 
                    copy($src . '/' . $file,$dst . '/' . $file); 
                } 
            } 
        } 
        closedir($dir); 
    }
747965
function _copyFileSync(src, dest, flag) {
    const SIZE = 65536;

    const COPYFILE_EXCL = 1;
    const COPYFILE_FICLONE = 2;
    const COPYFILE_FICLONE_FORCE = 4;

    const constants = {
        COPYFILE_EXCL,
        COPYFILE_FICLONE,
        COPYFILE_FICLONE_FORCE,
    };

    const isNumber = (a) => typeof a === 'number';
    const or = (a, b) => a | b;
    const getValue = (obj) => (key) => obj[key];

    const getMaxMask = (obj) => Object
          .keys(obj)
          .map(getValue(obj))
          .reduce(or);

    const MAX_MASK = getMaxMask(constants);
    const isExcl = (flags) => flags & COPYFILE_EXCL;


    const writeFlag = isExcl(flag) ? 'wx' : 'w';

    const {
        size,
        mode,
    } = fs.statSync(src);

    const fdSrc = fs.openSync(src, 'r');
    const fdDest = fs.openSync(dest, writeFlag, mode);

    const length = size < SIZE ? size : SIZE;

    let pos = 0;
    const peaceSize = size < SIZE ? 0 : size % SIZE;
    const offset = 0;

    let buffer = Buffer.allocUnsafe(length);
    for (let i = 0; length + pos + peaceSize <= size; i++, pos = length * i) {
        fs.readSync(fdSrc, buffer, offset, length, pos);
        fs.writeSync(fdDest, buffer, offset, length, pos);
    }

    if (peaceSize) {
        const length = peaceSize;
        buffer = Buffer.allocUnsafe(length);
        fs.readSync(fdSrc, buffer, offset, length, pos);
        fs.writeSync(fdDest, buffer, offset, length, pos);
    }

    fs.closeSync(fdSrc);
    fs.closeSync(fdDest);
}
571061
public static function copy($src, $dest, $force = false)
	{
		if (is_dir($src)) {
			Dir::copy($src, $dest, $force);
		} elseif (is_file($src)) {
			File::copy($src, $dest, $force);
		}

		return true;
	}
782344
public static function recurseCopyIfEdited($src = '', $dst = '', array $excludes = ['php'])
    {
        if (!is_dir($dst) && (!mkdir($dst) && !is_dir($dst))) {
            throw new Exception('Copy dir error, access denied for path: '.$dst);
        }

        $dir = opendir($src);
        if (!$dir) {
            throw new Exception('Unable to read dir: '.$src);
        }

        while (false !== ($file = readdir($dir))) {
            if ($file === '.' || $file === '..') {
                continue;
            }

            if (is_dir($src.'/'.$file)) {
                self::recurseCopyIfEdited($src.'/'.$file, $dst.'/'.$file, $excludes);
                continue;
            }

            if (in_array(substr($file, strrpos($file, '.') + 1), $excludes, null)) {
                continue;
            }


            if (file_exists($dst.'/'.$file) && (filemtime($src.'/'.$file) === filemtime($dst.'/'.$file))) {
                continue;
            }

            copy($src.'/'.$file, $dst.'/'.$file);
            chmod($dst.'/'.$file, 0666);
        }
        closedir($dir);
    }
563077
public static function copy_overwrite_files( $source, $dest ) {
		$iterator = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator( $source, RecursiveDirectoryIterator::SKIP_DOTS ),
			RecursiveIteratorIterator::SELF_FIRST
		);

		$error = 0;

		if ( ! is_dir( $dest ) ) {
			mkdir( $dest, 0777, true );
		}

		foreach ( $iterator as $item ) {

			$dest_path = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();

			if ( $item->isDir() ) {
				if ( ! is_dir( $dest_path ) ) {
					mkdir( $dest_path );
				}
			} else {
				if ( file_exists( $dest_path ) && is_writable( $dest_path ) ) {
					copy( $item, $dest_path );
				} elseif ( ! file_exists( $dest_path ) ) {
					copy( $item, $dest_path );
				} else {
					$error = 1;
					WP_CLI::warning( "Unable to copy '" . $iterator->getSubPathName() . "' to current directory." );
				}
			}
		}

		if ( $error ) {
			throw new \Exception( 'There was an error overwriting existing files.' );
		}
	}
799348
protected function move($src, $dst, $name) {
		$stat = $this->stat($src);
		$stat['realpath'] = $src;
		$this->rmTmb($stat); // can not do rmTmb() after _move()
		$this->clearcache();
		
		if ($this->convEncOut($this->_move($this->convEncIn($src), $this->convEncIn($dst), $this->convEncIn($name)))) {
			$this->removed[] = $stat;

			return $this->joinPathCE($dst, $name);
		}

		return $this->setError(elFinder::ERROR_MOVE, $this->path($src));
	}