Skip to content

Commit

Permalink
Clean up properly if self-update fails (#10475)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstevenson committed Jan 21, 2022
1 parent e3d99ca commit 0228e5b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Composer/Command/SelfUpdateCommand.php
Expand Up @@ -468,6 +468,7 @@ protected function setLocalPhar($localFilename, $newFilename, $backupTarget = nu
return $this->tryAsWindowsAdmin($localFilename, $newFilename);
}

@unlink($newFilename);
$action = 'Composer '.($backupTarget ? 'update' : 'rollback');
throw new FilesystemException($action.' failed: "'.$localFilename.'" could not be written.'.PHP_EOL.$e->getMessage());
}
Expand Down Expand Up @@ -620,7 +621,7 @@ protected function tryAsWindowsAdmin($localFilename, $newFilename)
exec('"'.$script.'"');
@unlink($script);

// see if the file was moved and is still accessible
// see if the file was copied and is still accessible
if ($result = Filesystem::isReadable($localFilename) && (hash_file('sha256', $localFilename) === $checksum)) {
$io->writeError('<info>Operation succeeded.</info>');
@unlink($newFilename);
Expand Down

0 comments on commit 0228e5b

Please sign in to comment.