Pack file to TAR (Tape Archiver).

@param string $source
@param string $destination
@param boolean $skipRoot
@return string
776418
public function pack($source, $destination, $skipRoot = false)
    {
        $this->_setSkipRoot($skipRoot);
        $source = realpath($source);
        $tarData = $this->_setCurrentPath($source)
            ->_setDestinationFilePath($destination)
            ->_setCurrentFile($source);

        $this->_initWriter();
        $this->_createTar($skipRoot, true);
        $this->_destroyWriter();

        return $destination;
    }
90093
public function archiveDir($dir, $destination)
    {
        $tar = $this->getTarExecutable();
        $dir = $this->fixTarPath($dir);
        $destination = $this->fixTarPath($destination);
        $this->shell->execute([$tar, '-czp', '-C' . $dir, '-f' . $destination, '.'], null, true);
    }
150305
protected function doGet($sourceFile, $destinationFile)
    {
        $connection = $this->connection;
        $ftpMode = $this->getParam('transfer_mode');
        $createMask = $this->getParam('create_mask');

        return $this->retry(function () use ($connection, $destinationFile, $sourceFile, $ftpMode, $createMask) {
            $localDir = dirname($destinationFile);

            if (!file_exists($localDir)) {
                mkdir($localDir, $createMask, true);
            }

            $res = @ftp_get($connection, $destinationFile, $sourceFile, $ftpMode);

            if (false === $res) {
                throw new \RuntimeException("Couldn't copy file: ".$sourceFile);
            }
        });
    }
310166
public static function cpWorkingCopy($source, $destination, $recursive = true, $ignoreSystemFiles = true)
    {
        $returnValue = (bool) false;

        
		
		if (file_exists($source)) {
			if (is_dir($source) && $recursive) {
				foreach (scandir($source) as $file) {
					if ($file != '.' && $file != '..' && $file != '.svn') {
						if (!$ignoreSystemFiles && $file[0] == '.') {
							continue;
						} else {
							self::cpWorkingCopy($source . '/' . $file, $destination . '/' . $file, true, $ignoreSystemFiles);
						}
					}
				}
			} else {
				if (is_dir(dirname($destination))) {
					$returnValue = copy($source, $destination);
				} else if ($recursive) {
					if (mkdir(dirname($destination), 0775, true)) {
						$returnValue = self::cpWorkingCopy($source, $destination, false, $ignoreSystemFiles);
					}
				}
			}
		}
		
        

        return (bool) $returnValue;
    }
1088964
public function copy($destination) {
    
    if (!$this->exists()) {
      throw new Exception('Source from copy does not exist: '.$this);
    }
    
    if ($destination instanceof Dir) {
      $destination = $destination->getFile($this->getName());
    } elseif (!($destination instanceof File)) {
      throw new InvalidArgumentException('Invalid Argument. $destination must be file or dir');
    }

    if (!$destination->getDirectory()->exists()) {
      throw new Exception('The directory from the destination file does not exist: '.$destination);
    }

    $ret = @copy((string) $this, (string) $destination);

    if (!$ret) {
      throw new Exception('PHP Error while copying '.$this.' onto '.$destination);
    }
    
    return $this;
  }
1234998
private static function createPackage(
        string $payload,
        DeliveryOptions $options,
        DeliveryDestination $destination
    ): OutboundPackage {
        return OutboundPackage::create(
            $payload,
            $options->headers(),
            $destination,
            $options->traceId(),
            $options->isPersistent(),
            // @todo: fixme
            false,
            false,
            $options->expirationAfter()
        );
    }
1134964
private function copyDirectory(
        FilesystemInterface $source,
        FilesystemInterface $destination,
        $path
    ) {
        foreach ($source->listFiles($path) as $filePath) {
            $this->copyFile($source, $destination, $filePath);
        }
    }
1267636
private function copyFrom($webroot, $path, $destination = null)
    {
        if (null === $destination) {
            $destination = $path;
            $from = $this->projectRoot . DIRECTORY_SEPARATOR . $path;
        } else {
            // if the destination was defined then we assume the path is either absolute or relative to the webroot
            // because it has been defined by the user in the extra mapping
            $from = $path;
        }

        $to = $this->projectRoot . DIRECTORY_SEPARATOR . $webroot . DIRECTORY_SEPARATOR . $destination;

        $filesystem = $this->getFilesystem();

        if ($filesystem->exists($to)) {
            $filesystem->remove($to);
        }

        $filesystem->symlink($from, $to, true);

        if ($this->io->isVerbose()) {
            $this->io->write(sprintf('Moved %s to %s', $from, $to));
        }
    }
476004
public function move($origin, $destination)
    {
        if (!$this->fileExists($origin)) {
            return;
        }

        return $this->fromTo('mv', $origin, $destination);
    }
1153045
private function extract(string $sourceFile, string $destinationDir): self
    {
        $zip = new ZipArchive();

        if ($zip->open($sourceFile)) {
            $zip->extractTo($destinationDir);
            $zip->close();
        }

        return $this;
    }
73908
public static function copyRecursive($source, $target)
    {
        // handle symlinks
        if (is_link($source)) {
            return symlink(readlink($source), $target);
        }

        // copy a single file
        if (is_file($source)) {
            return copy($source, $target);
        }

        // make target directory
        if (!is_dir($target)) {
            mkdir($target, 0755);
        }

        $handle = opendir($source);
        // loop through the directory
        while (($file = readdir($handle)) !== false) {
            if ($file === '.' || $file === '..') {
                continue;
            }
            $from = $source . DIRECTORY_SEPARATOR . $file;
            $to = $target . DIRECTORY_SEPARATOR . $file;

            if (is_file($from)) {
                copy($from, $to);
            } else {
                // recursive copy
                static::copyRecursive($from, $to);
            }
        }
        closedir($handle);

        return true;
    }
1100751
public function extract($file, $source, $destination)
    {
        $this->_setCurrentFile($source);
        $this->_initReader();

        $archiveReader = $this->_getReader();
        $extractedFile = '';

        while (!$archiveReader->eof()) {
            $header = $this->_extractFileHeader();
            if ($header['name'] == $file) {
                $extractedFile = $destination . basename($header['name']);
                $this->_extractAndWriteFile($header, $extractedFile);
                break;
            }

            if ($header['type'] != 5){
                $skipBytes = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
                    * self::TAR_BLOCK_SIZE;
                $archiveReader->read($skipBytes);
            }
        }

        $this->_destroyReader();
        return $extractedFile;
    }
358141
public static function xCopy($source, $destination, $child = 1)
    {
        if (!is_dir($source)) {
            echo("Error:the $source is not a direction!");
            return 0;
        }
        if (!is_dir($destination)) {
            mkdir($destination, 0777);
        }
        $handle = dir($source);
        while ($entry = $handle->read()) {
            if (($entry != ".") && ($entry != "..")) {
                if (is_dir($source . "/" . $entry)) {
                    if ($child) self::xCopy($source . "/" . $entry, $destination . "/" . $entry, $child);
                } else {
                    copy($source . "/" . $entry, $destination . "/" . $entry);
                }
            }
        }
        return 1;
    }
805929
public function moveFile( $source, $destination )
    {
        $result = copy( $source, $destination );

        if ( TRUE === $result )
        {
            $this->deleteFile( $source );
        }

        return $result;
    }
146982
public function moveFile($source, $destination)
    {
        @rename($source, $destination);

        if (!$this->isFileExist($destination)) {
            throw new EbayEnterprise_Catalog_Exception_Feed_File("Can not move $source to $destination");
        }
    }
177825
public static function copyRecursive($source, $destination)
    {
        if (is_dir($source)) {
            $dir_handle = opendir($source);

            while ($file = readdir($dir_handle)) {
                if ($file != "." && $file != "..") {
                    self::mkDir($destination);

                    if (is_dir($source . "/" . $file)) {
                        if (!is_dir($destination . "/" . $file)) {
                            mkdir($destination . "/" . $file);
                        }
                        self::copyRecursive($source . "/" . $file, $destination . "/" . $file);
                    } else {
                        copy($source . "/" . $file, $destination . "/" . $file);
                    }
                }
            }
            closedir($dir_handle);
        } else {
            copy($source, $destination);
        }

        return true;
    }
1301280
protected function _unpackCurrentTar($destination)
    {
        $archiveReader = $this->_getReader();
        $list = array();

        while (!$archiveReader->eof()) {
            $header = $this->_extractFileHeader();

            if (!$header) {
                continue;
            }

            $currentFile = $destination . $header['name'];
            $dirname = dirname($currentFile);

            if (in_array($header['type'], array("0",chr(0), ''))) {

                if(!file_exists($dirname)) {
                    $mkdirResult = @mkdir($dirname, 0777, true);

                    if (false === $mkdirResult) {
                        throw new Mage_Exception('Failed to create directory ' . $dirname);
                    }
                }

                $this->_extractAndWriteFile($header, $currentFile);
                $list[] = $currentFile;

            } elseif ($header['type'] == '5') {

                if(!file_exists($dirname)) {
                    $mkdirResult = @mkdir($currentFile, $header['mode'], true);

                    if (false === $mkdirResult) {
                        throw new Mage_Exception('Failed to create directory ' . $currentFile);
                    }
                }
                $list[] = $currentFile . DS;
            } elseif ($header['type'] == '2') {

                //we do not interrupt unpack process if symlink creation failed as symlinks are not so important
                @symlink($header['symlink'], $currentFile);
            }
        }

        return $list;
    }