浏览代码

Small tweaks and make sure composer fails properly in a plane

Jordi Boggiano 6 年之前
父节点
当前提交
4b7658a2a8
共有 2 个文件被更改,包括 9 次插入3 次删除
  1. 7 2
      src/Composer/Repository/ComposerRepository.php
  2. 2 1
      src/Composer/Util/Http/CurlDownloader.php

+ 7 - 2
src/Composer/Repository/ComposerRepository.php

@@ -250,13 +250,18 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
             foreach ($packageNameMap as $name => $constraint) {
                 $matches = array();
 
+                // if a repo has no providers but only partial packages and the partial packages are missing
+                // then we don't want to call whatProvides as it would try to load from the providers and fail
                 if (!$hasProviders && !isset($this->partialPackagesByName[$name])) {
                     continue;
                 }
 
                 $candidates = $this->whatProvides($name, $isPackageAcceptableCallable);
                 foreach ($candidates as $candidate) {
-                    if ($candidate->getName() === $name && (!$constraint || $constraint->matches(new Constraint('==', $candidate->getVersion())))) {
+                    if ($candidate->getName() !== $name) {
+                        throw new \LogicException('whatProvides should never return a package with a different name than the requested one');
+                    }
+                    if (!$constraint || $constraint->matches(new Constraint('==', $candidate->getVersion()))) {
                         $matches[spl_object_hash($candidate)] = $candidate;
                         if ($candidate instanceof AliasPackage && !isset($matches[spl_object_hash($candidate->getAliasOf())])) {
                             $matches[spl_object_hash($candidate->getAliasOf())] = $candidate->getAliasOf();
@@ -278,7 +283,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
             return $packages;
         }
 
-        if ($this->lazyProvidersUrl) {
+        if ($this->lazyProvidersUrl && count($packageNameMap)) {
             $packages = array_merge($packages, $this->loadAsyncPackages($packageNameMap, $isPackageAcceptableCallable));
         }
 

+ 2 - 1
src/Composer/Util/Http/CurlDownloader.php

@@ -225,6 +225,7 @@ class CurlDownloader
             if (!isset($this->jobs[$i])) {
                 continue;
             }
+
             $progress = array_diff_key(curl_getinfo($curlHandle), self::$timeInfo);
             $job = $this->jobs[$i];
             unset($this->jobs[$i]);
@@ -239,7 +240,7 @@ class CurlDownloader
             try {
 // TODO progress
                 //$this->onProgress($curlHandle, $job['callback'], $progress, $job['progress']);
-                if (CURLE_OK !== $errno) {
+                if (CURLE_OK !== $errno || $error) {
                     throw new TransportException($error);
                 }