Skip to content

Commit

Permalink
drupal-composer#102 Update CurlMulti code with Prefetcher.php from pr…
Browse files Browse the repository at this point in the history
…estissimo
  • Loading branch information
Schnitzel authored Feb 28, 2019
1 parent 756910b commit e53370c
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/PrestissimoFileFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,24 @@ protected function fetchWithPrestissimo($version, $destination, $override) {

$multi = new CurlMulti();
$multi->setRequests($requests);
do {
$multi->setupEventLoop();
$multi->wait();
$result = $multi->getFinishedResults();
$successCnt += $result['successCnt'];
$failureCnt += $result['failureCnt'];
if (isset($result['errors'])) {
$errors += $result['errors'];
}
if ($this->progress) {
foreach ($result['urls'] as $url) {
$this->io->writeError(" - Downloading <comment>$successCnt</comment>/<comment>$totalCnt</comment>: <info>$url</info>", TRUE);
}
}
} while ($multi->remain());

$urls = array_keys($errors);
if ($urls) {
throw new \Exception('Failed to download ' . implode(", ", $urls));
}
try {
do {
$multi->setupEventLoop();
$multi->wait();
$result = $multi->getFinishedResults();
$successCnt += $result['successCnt'];
$failureCnt += $result['failureCnt'];
foreach ($result['urls'] as $url) {
if (isset($result['errors'][$url])) {
$this->io->writeError(" - Downloading <warning>$successCnt</warning>/<warning>$totalCnt</warning>: <warning>$url</warning>", TRUE);
} else {
$this->io->writeError(" - Downloading <comment>$successCnt</comment>/<comment>$totalCnt</comment>: <info>$url</info>", TRUE);
}
}
} while ($multi->remain());
} catch (FetchException $e) {
// do nothing
}
}

}

0 comments on commit e53370c

Please sign in to comment.