Make overwriting files an ArchiveManager option, use sourceRef in names
parent
6ee08a2046
commit
64941b0a64
|
@ -29,6 +29,11 @@ class ArchiveManager
|
||||||
|
|
||||||
protected $archivers = array();
|
protected $archivers = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $overwriteFiles = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DownloadManager $downloadManager A manager used to download package sources
|
* @param DownloadManager $downloadManager A manager used to download package sources
|
||||||
*/
|
*/
|
||||||
|
@ -45,6 +50,19 @@ class ArchiveManager
|
||||||
$this->archivers[] = $archiver;
|
$this->archivers[] = $archiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether existing archives should be overwritten
|
||||||
|
*
|
||||||
|
* @param bool $overwriteFiles New setting
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setOverwriteFiles($overwriteFiles)
|
||||||
|
{
|
||||||
|
$this->overwriteFiles = $overwriteFiles;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a distinct filename for a particular version of a package.
|
* Generate a distinct filename for a particular version of a package.
|
||||||
*
|
*
|
||||||
|
@ -62,10 +80,13 @@ class ArchiveManager
|
||||||
$nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference()));
|
$nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($package->getSourceReference()) {
|
||||||
|
$nameParts[] = substr(sha1($package->getSourceReference()), 0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
return implode('-', array_filter($nameParts, function ($p) {
|
return implode('-', array_filter($nameParts, function ($p) {
|
||||||
return !empty($p);
|
return !empty($p);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,6 +126,10 @@ class ArchiveManager
|
||||||
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
||||||
$filesystem->ensureDirectoryExists(dirname($target));
|
$filesystem->ensureDirectoryExists(dirname($target));
|
||||||
|
|
||||||
|
if (!$this->overwriteFiles && file_exists($target)) {
|
||||||
|
return $target;
|
||||||
|
}
|
||||||
|
|
||||||
if ($package instanceof RootPackage) {
|
if ($package instanceof RootPackage) {
|
||||||
$sourcePath = realpath('.');
|
$sourcePath = realpath('.');
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +142,6 @@ class ArchiveManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the archive
|
// Create the archive
|
||||||
$sourceRef = $package->getSourceReference();
|
return $usableArchiver->archive($sourcePath, $target, $format, $package->getArchiveExcludes());
|
||||||
return $usableArchiver->archive($sourcePath, $target, $format, $sourceRef, $package->getArchiveExcludes());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,11 @@ interface ArchiverInterface
|
||||||
* @param string $sources The sources directory
|
* @param string $sources The sources directory
|
||||||
* @param string $target The target file
|
* @param string $target The target file
|
||||||
* @param string $format The format used for archive
|
* @param string $format The format used for archive
|
||||||
* @param string $sourceRef The reference of the source to archive or null
|
|
||||||
* for the current reference
|
|
||||||
* @param array $excludes A list of patterns for files to exclude
|
* @param array $excludes A list of patterns for files to exclude
|
||||||
*
|
*
|
||||||
* @return string The path to the written archive file
|
* @return string The path to the written archive file
|
||||||
*/
|
*/
|
||||||
public function archive($sources, $target, $format, $sourceRef = null, $excludes = array());
|
public function archive($sources, $target, $format, $excludes = array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format supported by the archiver.
|
* Format supported by the archiver.
|
||||||
|
|
|
@ -32,7 +32,7 @@ class PharArchiver implements ArchiverInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function archive($sources, $target, $format, $sourceRef = null, $excludes = array())
|
public function archive($sources, $target, $format, $excludes = array())
|
||||||
{
|
{
|
||||||
$sources = realpath($sources);
|
$sources = realpath($sources);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue