Эх сурвалжийг харах

Remove forced dir removal before install, fixes #3035

Jordi Boggiano 11 жил өмнө
parent
commit
71397f82e4

+ 1 - 2
src/Composer/Downloader/FileDownloader.php

@@ -107,8 +107,7 @@ class FileDownloader implements DownloaderInterface
 
     protected function doDownload(PackageInterface $package, $path, $url)
     {
-        $this->filesystem->removeDirectory($path);
-        $this->filesystem->ensureDirectoryExists($path);
+        $this->filesystem->emptyDirectory($path);
 
         $fileName = $this->getFileName($package, $path);
 

+ 1 - 1
src/Composer/Downloader/VcsDownloader.php

@@ -55,7 +55,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
         }
 
         $this->io->write("  - Installing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)");
-        $this->filesystem->removeDirectory($path);
+        $this->filesystem->emptyDirectory($path);
 
         $urls = $package->getSourceUrls();
         while ($url = array_shift($urls)) {

+ 19 - 1
src/Composer/Util/Filesystem.php

@@ -74,7 +74,25 @@ class Filesystem
     {
         $dir = rtrim($dir, '/\\');
 
-        return count($this->realpathGlob($dir.'/*') ?: array()) === 0 && count($this->realpathGlob($dir.'/.*') ?: array()) === 2;
+        return count($this->realpathGlob($dir.'/*')) === 0 && count($this->realpathGlob($dir.'/.*')) === 2;
+    }
+
+    public function emptyDirectory($dir, $ensureDirectoryExists = true)
+    {
+        if ($ensureDirectoryExists) {
+            $this->ensureDirectoryExists($dir);
+        }
+
+        if (is_dir($dir)) {
+            foreach ($this->realpathGlob(rtrim($dir, '\\/').'/*') as $path) {
+                $this->remove($path);
+            }
+            foreach ($this->realpathGlob(rtrim($dir, '\\/').'/.*') as $path) {
+                if (basename($path) !== '..' && basename($path) !== '.') {
+                    $this->remove($path);
+                }
+            }
+        }
     }
 
     /**