浏览代码

Fix create-project command

Jordi Boggiano 5 年之前
父节点
当前提交
8a83d5cc35
共有 2 个文件被更改,包括 22 次插入2 次删除
  1. 0 2
      src/Composer/Command/CreateProjectCommand.php
  2. 22 0
      src/Composer/Downloader/DownloadManager.php

+ 0 - 2
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) {

+ 22 - 0
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, '\\/');
+    }
 }