Skip to content

Commit

Permalink
avoid >100% progress
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed May 30, 2020
1 parent a530568 commit dcc71c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/build/
.phpunit.result.cache
.php_cs.cache
composer.lock
3 changes: 2 additions & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'fopen_flags' => false,
'@PHPUnit48Migration:risky' => true,
'array_syntax' => array('syntax' => 'short'),
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
'protected_to_private' => false,
Expand Down
12 changes: 11 additions & 1 deletion src/CurlDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public function get($origin, $url, $context, $file)
if ($file && !isset($this->exceptions[(int) $ch])) {
$fd = fopen($file, 'rb');
}
$progress = array_diff_key(curl_getinfo($ch), self::$timeInfo);
$this->finishProgress($ch, $params['notification'], $progress);
unset($this->jobs[(int) $ch], $this->exceptions[(int) $ch]);
curl_multi_remove_handle($this->multiHandle, $ch);
curl_close($ch);
Expand All @@ -186,7 +188,7 @@ public function get($origin, $url, $context, $file)

private function onProgress($ch, callable $notify, array $progress, array $previousProgress)
{
if (300 <= $progress['http_code'] && $progress['http_code'] < 400) {
if (300 <= $progress['http_code'] && $progress['http_code'] < 400 || 0 > $progress['download_content_length']) {
return;
}

Expand All @@ -203,4 +205,12 @@ private function onProgress($ch, callable $notify, array $progress, array $previ
$notify(STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['download_content_length'], false);
}
}

private function finishProgress($ch, callable $notify, array $progress)
{
if ($progress['download_content_length'] < 0) {
$notify(STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, (int) $progress['size_download'], false);
$notify(STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['size_download'], false);
}
}
}

0 comments on commit dcc71c2

Please sign in to comment.