function PathDownloader::remove
@inheritDoc
Overrides FileDownloader::remove
File
-
vendor/
composer/ composer/ src/ Composer/ Downloader/ PathDownloader.php, line 173
Class
- PathDownloader
- Download a package from a local path.
Namespace
Composer\DownloaderCode
public function remove(PackageInterface $package, string $path, bool $output = true) : PromiseInterface {
$path = Filesystem::trimTrailingSlash($path);
/**
* realpath() may resolve Windows junctions to the source path, so we'll check for a junction first
* to prevent a false positive when checking if the dist and install paths are the same.
* See https://bugs.php.net/bug.php?id=77639
*
* For junctions don't blindly rely on Filesystem::removeDirectory as it may be overzealous. If a process
* inadvertently locks the file the removal will fail, but it would fall back to recursive delete which
* is disastrous within a junction. So in that case we have no other real choice but to fail hard.
*/
if (Platform::isWindows() && $this->filesystem
->isJunction($path)) {
if ($output) {
$this->io
->writeError(" - " . UninstallOperation::format($package) . ", source is still present in {$path}");
}
if (!$this->filesystem
->removeJunction($path)) {
$this->io
->writeError(" <warning>Could not remove junction at " . $path . " - is another process locking it?</warning>");
throw new \RuntimeException('Could not reliably remove junction for package ' . $package->getName());
}
return \React\Promise\resolve(null);
}
$url = $package->getDistUrl();
if (null === $url) {
throw new \RuntimeException('The package ' . $package->getPrettyName() . ' has no dist url configured, cannot remove.');
}
// ensure that the source path (dist url) is not the same as the install path, which
// can happen when using custom installers, see https://github.com/composer/composer/pull/9116
// not using realpath here as we do not want to resolve the symlink to the original dist url
// it points to
$fs = new Filesystem();
$absPath = $fs->isAbsolutePath($path) ? $path : Platform::getCwd() . '/' . $path;
$absDistUrl = $fs->isAbsolutePath($url) ? $url : Platform::getCwd() . '/' . $url;
if ($fs->normalizePath($absPath) === $fs->normalizePath($absDistUrl)) {
if ($output) {
$this->io
->writeError(" - " . UninstallOperation::format($package) . ", source is still present in {$path}");
}
return \React\Promise\resolve(null);
}
return parent::remove($package, $path, $output);
}