1
0
Fork 0

Also clean backups if no Composer update actually performed

pull/4995/head
vlakoff 2016-03-03 18:49:21 +01:00
parent 496d29a793
commit 93e08fd78e
1 changed files with 9 additions and 1 deletions

View File

@ -105,6 +105,11 @@ EOT
if (Composer::VERSION === $updateVersion) { if (Composer::VERSION === $updateVersion) {
$io->writeError('<info>You are already using composer version '.$updateVersion.'.</info>'); $io->writeError('<info>You are already using composer version '.$updateVersion.'.</info>');
// remove all backups except for the most recent, if any
if ($input->getOption('clean-backups')) {
$this->cleanBackups($rollbackDir, $this->getLastBackupVersion());
}
return 0; return 0;
} }
@ -315,13 +320,16 @@ TAGSPUBKEY
} }
} }
protected function cleanBackups($rollbackDir) protected function cleanBackups($rollbackDir, $except = null)
{ {
$finder = $this->getOldInstallationFinder($rollbackDir); $finder = $this->getOldInstallationFinder($rollbackDir);
$io = $this->getIO(); $io = $this->getIO();
$fs = new Filesystem; $fs = new Filesystem;
foreach ($finder as $file) { foreach ($finder as $file) {
if ($except && $file->getBasename(self::OLD_INSTALL_EXT) === $except) {
continue;
}
$file = (string) $file; $file = (string) $file;
$io->writeError('<info>Removing: '.$file.'</info>'); $io->writeError('<info>Removing: '.$file.'</info>');
$fs->remove($file); $fs->remove($file);