1
0
Fork 0

Allow COMPOSER_DISABLE_NETWORK to work with GitHubDriver by doing a cache priming pass first

pull/8752/head
Jordi Boggiano 2020-04-08 17:53:15 +02:00
parent 9575c7623f
commit aa6be02c64
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
5 changed files with 21 additions and 8 deletions

View File

@ -958,4 +958,7 @@ can also set it to `*` to ignore the proxy for all HTTP requests.
If set to `1`, disables network access (best effort). This can be used for debugging or If set to `1`, disables network access (best effort). This can be used for debugging or
to run Composer on a plane or a starship with poor connectivity. to run Composer on a plane or a starship with poor connectivity.
If set to `prime`, GitHub VCS repositories will prime the cache so it can then be used
fully offline with `1`.
← [Libraries](02-libraries.md) | [Schema](04-schema.md) → ← [Libraries](02-libraries.md) | [Schema](04-schema.md) →

View File

@ -1065,8 +1065,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
if ($cacheKey && ($contents = $this->cache->read($cacheKey))) { if ($cacheKey && ($contents = $this->cache->read($cacheKey))) {
if (!$this->degradedMode) { if (!$this->degradedMode) {
$this->io->writeError('<warning>'.$e->getMessage().'</warning>'); $this->io->writeError('<warning>'.$this->url.' could not be fully loaded ('.$e->getMessage().'), package information was loaded from the local cache and may be out of date</warning>');
$this->io->writeError('<warning>'.$this->url.' could not be fully loaded, package information was loaded from the local cache and may be out of date</warning>');
} }
$this->degradedMode = true; $this->degradedMode = true;
$data = JsonFile::parseJson($contents, $this->cache->getRoot().$cacheKey); $data = JsonFile::parseJson($contents, $this->cache->getRoot().$cacheKey);
@ -1133,8 +1132,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
} }
if (!$this->degradedMode) { if (!$this->degradedMode) {
$this->io->writeError('<warning>'.$e->getMessage().'</warning>'); $this->io->writeError('<warning>'.$this->url.' could not be fully loaded ('.$e->getMessage().'), package information was loaded from the local cache and may be out of date</warning>');
$this->io->writeError('<warning>'.$this->url.' could not be fully loaded, package information was loaded from the local cache and may be out of date</warning>');
} }
$this->degradedMode = true; $this->degradedMode = true;
@ -1209,8 +1207,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
} }
if (!$degradedMode) { if (!$degradedMode) {
$io->writeError('<warning>'.$e->getMessage().'</warning>'); $io->writeError('<warning>'.$url.' could not be fully loaded ('.$e->getMessage().'), package information was loaded from the local cache and may be out of date</warning>');
$io->writeError('<warning>'.$url.' could not be fully loaded, package information was loaded from the local cache and may be out of date</warning>');
} }
$degradedMode = true; $degradedMode = true;

View File

@ -62,6 +62,9 @@ class GitDriver extends VcsDriver
$gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs); $gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
if (!$gitUtil->syncMirror($this->url, $this->repoDir)) { if (!$gitUtil->syncMirror($this->url, $this->repoDir)) {
if (!is_dir($this->repoDir)) {
throw new \RuntimeException('Failed to clone '.$this->url.' to read package information from it');
}
$this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated</error>'); $this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated</error>');
} }

View File

@ -507,7 +507,15 @@ class GitHubDriver extends VcsDriver
$repoDataUrl = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository; $repoDataUrl = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository;
$this->repoData = $this->getContents($repoDataUrl, true)->decodeJson(); try {
$this->repoData = $this->getContents($repoDataUrl, true)->decodeJson();
} catch (TransportException $e) {
if ($e->getCode() === 499) {
$this->attemptCloneFallback();
} else {
throw $e;
}
}
if (null === $this->repoData && null !== $this->gitDriver) { if (null === $this->repoData && null !== $this->gitDriver) {
return; return;
} }

View File

@ -248,7 +248,9 @@ class Git
public function syncMirror($url, $dir) public function syncMirror($url, $dir)
{ {
if (getenv('COMPOSER_DISABLE_NETWORK')) { if (getenv('COMPOSER_DISABLE_NETWORK') && getenv('COMPOSER_DISABLE_NETWORK') !== 'prime') {
$this->io->writeError('<warning>Aborting git mirror sync of '.$url.' as network is disabled</warning>');
return false; return false;
} }