From 52caea70d4453173e3ad02941b323b7fc0e2d7c1 Mon Sep 17 00:00:00 2001 From: Sergii Shymko Date: Tue, 6 Jun 2023 06:54:17 -0500 Subject: [PATCH] Refactor downloader package dist path parsing (#11471) --- src/Composer/Downloader/FileDownloader.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 300a7e604..49baa6321 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -353,7 +353,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface $this->filesystem->emptyDirectory($path); $this->filesystem->ensureDirectoryExists($path); - $this->filesystem->rename($this->getFileName($package, $path), $path . '/' . pathinfo(parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), PATHINFO_BASENAME)); + $this->filesystem->rename($this->getFileName($package, $path), $path . '/' . $this->getDistPath($package, PATHINFO_BASENAME)); if ($package->getBinaries()) { // Single files can not have a mode set like files in archives @@ -368,6 +368,12 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface return \React\Promise\resolve(null); } + protected function getDistPath(PackageInterface $package, int $component): string + { + // @phpstan-ignore-next-line + return pathinfo((string) parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), $component); + } + protected function clearLastCacheWrite(PackageInterface $package): void { if ($this->cache && isset($this->lastCacheWrites[$package->getName()])) { @@ -431,7 +437,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface */ protected function getFileName(PackageInterface $package, string $path): string { - return rtrim($this->config->get('vendor-dir').'/composer/tmp-'.md5($package.spl_object_hash($package)).'.'.pathinfo(parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), PATHINFO_EXTENSION), '.'); + return rtrim($this->config->get('vendor-dir') . '/composer/tmp-' . md5($package . spl_object_hash($package)) . '.' . $this->getDistPath($package, PATHINFO_EXTENSION), '.'); } /**