From 8a83d5cc353ea3f561226a01accb92bbe2539cc0 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 12 Mar 2020 13:50:18 +0100 Subject: [PATCH] Fix create-project command --- src/Composer/Command/CreateProjectCommand.php | 2 -- src/Composer/Downloader/DownloadManager.php | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 52c75a609..9263ba7ee 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -183,8 +183,6 @@ EOT $composer = Factory::create($io, null, $disablePlugins); } - $composer->getDownloadManager()->setOutputProgress(!$noProgress); - $fs = new Filesystem(); if ($noScripts === false) { diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 794998bb2..3ee786c17 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -175,6 +175,7 @@ class DownloadManager */ public function download(PackageInterface $package, $targetDir, PackageInterface $prevPackage = null) { + $targetDir = $this->normalizeTargetDir($targetDir); $this->filesystem->ensureDirectoryExists(dirname($targetDir)); $sources = $this->getAvailableSources($package, $prevPackage); @@ -244,6 +245,7 @@ class DownloadManager */ public function prepare($type, PackageInterface $package, $targetDir, PackageInterface $prevPackage = null) { + $targetDir = $this->normalizeTargetDir($targetDir); $downloader = $this->getDownloaderForPackage($package); if ($downloader) { return $downloader->prepare($type, $package, $targetDir, $prevPackage); @@ -262,6 +264,7 @@ class DownloadManager */ public function install(PackageInterface $package, $targetDir) { + $targetDir = $this->normalizeTargetDir($targetDir); $downloader = $this->getDownloaderForPackage($package); if ($downloader) { return $downloader->install($package, $targetDir); @@ -280,6 +283,7 @@ class DownloadManager */ public function update(PackageInterface $initial, PackageInterface $target, $targetDir) { + $targetDir = $this->normalizeTargetDir($targetDir); $downloader = $this->getDownloaderForPackage($target); $initialDownloader = $this->getDownloaderForPackage($initial); @@ -332,6 +336,7 @@ class DownloadManager */ public function remove(PackageInterface $package, $targetDir) { + $targetDir = $this->normalizeTargetDir($targetDir); $downloader = $this->getDownloaderForPackage($package); if ($downloader) { return $downloader->remove($package, $targetDir); @@ -350,6 +355,7 @@ class DownloadManager */ public function cleanup($type, PackageInterface $package, $targetDir, PackageInterface $prevPackage = null) { + $targetDir = $this->normalizeTargetDir($targetDir); $downloader = $this->getDownloaderForPackage($package); if ($downloader) { return $downloader->cleanup($type, $package, $targetDir, $prevPackage); @@ -422,4 +428,20 @@ class DownloadManager return $sources; } + + /** + * Downloaders expect a /path/to/dir without trailing slash + * + * If any Installer provides a path with a trailing slash, this can cause bugs so make sure we remove them + * + * @return string + */ + private function normalizeTargetDir($dir) + { + if ($dir === '\\' || $dir === '/') { + return $dir; + } + + return rtrim($dir, '\\/'); + } }