Skip to content

Commit

Permalink
Merge pull request #12 from phar-io/feature/improve-uninstall
Browse files Browse the repository at this point in the history
Check for write permissions before deleting phar
  • Loading branch information
sebastianfeldmann authored Nov 23, 2020
2 parents 2e7a530 + 48fdc1c commit 47855ea
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/ConfiguredMediator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ private function removePhars(): void

/** @var \PharIo\ComposerDistributor\File $phar */
foreach ($config->phars() as $phar) {
$pharLocation = $binDir . DIRECTORY_SEPARATOR . $phar->pharName();
if (is_file($pharLocation)) {
$this->io->write(sprintf(
'remove phar \'%1$s\'',
$phar->pharName()
));
unlink($pharLocation);
$this->deleteFile($phar, $binDir);
}
}

private function deleteFile(File $phar, string $binDir): void
{
$pharLocation = $binDir . DIRECTORY_SEPARATOR . $phar->pharName();
if (is_file($pharLocation)) {
if (!is_writable($pharLocation)) {
$this->io->write(sprintf('can not remove phar \'%1$s\' (insufficient permissions)', $phar->pharName()));
return;
}
$this->io->write(sprintf('remove phar \'%1$s\'', $phar->pharName()));
unlink($pharLocation);
}
}
}

0 comments on commit 47855ea

Please sign in to comment.