Explorar o código

Fix: Fail fast when the project directory is not empty

Avoid waiting until after `getBestCandidate()` has finished, as it can add notably delay on slow connections due to downloading megabytes of data. Only to fail if the install location is invalid.
polarathene %!s(int64=5) %!d(string=hai) anos
pai
achega
e5e8736383
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      src/Composer/Command/CreateProjectCommand.php

+ 5 - 0
src/Composer/Command/CreateProjectCommand.php

@@ -279,6 +279,11 @@ EOT
             $packageVersion = $requirements[0]['version'];
         }
 
+        $fs = new Filesystem();
+        if (is_dir($directory) && !$fs->isDirEmpty($directory)) {
+            throw new \InvalidArgumentException("Project directory $directory is not empty.");
+        }
+
         if (null === $stability) {
             if (preg_match('{^[^,\s]*?@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $packageVersion, $match)) {
                 $stability = $match[1];