Skip to content

Commit f850efc

Browse files
bug #628 avoid >100% progress (IonBazan)
This PR was merged into the 1.7-dev branch. Discussion ---------- avoid >100% progress Fixes #468 This change skips tracking the progress of downloads where `Content-Length` header is missing. Curl returns `-1` which resulted in wrong progress calculation (total file size was not added to the total bytes to download). As soon as such file is downloaded, the progress is updated. This means that downloading one big file might cause progress to stuck until the download is done. Commits ------- dcc71c2 avoid >100% progress
2 parents a530568 + dcc71c2 commit f850efc

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor/
22
/build/
3+
.phpunit.result.cache
34
.php_cs.cache
45
composer.lock

.php_cs.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ return PhpCsFixer\Config::create()
77
->setRules(array(
88
'@Symfony' => true,
99
'@Symfony:risky' => true,
10+
'fopen_flags' => false,
1011
'@PHPUnit48Migration:risky' => true,
11-
'array_syntax' => array('syntax' => 'short'),
12+
'array_syntax' => ['syntax' => 'short'],
1213
'ordered_imports' => true,
1314
'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
1415
'protected_to_private' => false,

src/CurlDownloader.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ public function get($origin, $url, $context, $file)
168168
if ($file && !isset($this->exceptions[(int) $ch])) {
169169
$fd = fopen($file, 'rb');
170170
}
171+
$progress = array_diff_key(curl_getinfo($ch), self::$timeInfo);
172+
$this->finishProgress($ch, $params['notification'], $progress);
171173
unset($this->jobs[(int) $ch], $this->exceptions[(int) $ch]);
172174
curl_multi_remove_handle($this->multiHandle, $ch);
173175
curl_close($ch);
@@ -186,7 +188,7 @@ public function get($origin, $url, $context, $file)
186188

187189
private function onProgress($ch, callable $notify, array $progress, array $previousProgress)
188190
{
189-
if (300 <= $progress['http_code'] && $progress['http_code'] < 400) {
191+
if (300 <= $progress['http_code'] && $progress['http_code'] < 400 || 0 > $progress['download_content_length']) {
190192
return;
191193
}
192194

@@ -203,4 +205,12 @@ private function onProgress($ch, callable $notify, array $progress, array $previ
203205
$notify(STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['download_content_length'], false);
204206
}
205207
}
208+
209+
private function finishProgress($ch, callable $notify, array $progress)
210+
{
211+
if ($progress['download_content_length'] < 0) {
212+
$notify(STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, (int) $progress['size_download'], false);
213+
$notify(STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['size_download'], false);
214+
}
215+
}
206216
}

0 commit comments

Comments
 (0)