1
0
Fork 0

Generate a properly unique archive filename for dev revisions

pull/1567/head
Nils Adermann 2013-02-25 16:20:19 +01:00
parent 0b23643a44
commit 48dd55b759
1 changed files with 24 additions and 1 deletions

View File

@ -45,6 +45,29 @@ class ArchiveManager
$this->archivers[] = $archiver;
}
/**
* Generate a distinct filename for a particular version of a package.
*
* @param PackageInterface $package The package to get a name for
*
* @return string A filename without an extension
*/
protected function getPackageFilename(PackageInterface $package)
{
$nameParts = array(preg_replace('#[^a-z0-9-_.]#i', '-', $package->getName()));
if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
$nameParts = array_merge($nameParts, array($package->getDistReference(), $package->getDistType()));
} else {
$nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference(), $package->getDistType()));
}
return implode('-', array_filter($nameParts, function ($p) {
return !empty($p);
}));
}
/**
* Create an archive of the specified package.
*
@ -75,7 +98,7 @@ class ArchiveManager
}
$filesystem = new Filesystem();
$packageName = preg_replace('#[^a-z0-9-_.]#i', '-', $package->getPrettyString());
$packageName = $this->getPackageFilename($package);
// Archive filename
$filesystem->ensureDirectoryExists($targetDir);