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