浏览代码

[DownloadFile] Renamed wrapper directory after extract

This fixes error when the extracted directory (from an archive) contains
a folder with the same name. Example:

    $ mv test/test test
    mv: test/test and test/test are identical
MattKetmo 13 年之前
父节点
当前提交
7d5ba2d756
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      src/Composer/Downloader/FileDownloader.php

+ 7 - 0
src/Composer/Downloader/FileDownloader.php

@@ -111,6 +111,13 @@ abstract class FileDownloader implements DownloaderInterface
         $contentDir = glob($path . '/*');
         $contentDir = glob($path . '/*');
         if (1 === count($contentDir)) {
         if (1 === count($contentDir)) {
             $contentDir = $contentDir[0];
             $contentDir = $contentDir[0];
+
+            // Rename the content directory to avoid error when moving up
+            // a child folder with the same name
+            $temporaryName = md5(time().rand());
+            rename($contentDir, $temporaryName);
+            $contentDir = $temporaryName;
+
             foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) {
             foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) {
                 if (trim(basename($file), '.')) {
                 if (trim(basename($file), '.')) {
                     rename($file, $path . '/' . basename($file));
                     rename($file, $path . '/' . basename($file));