Skip to content

Commit dcc71c2

Browse files
committed
avoid >100% progress
1 parent a530568 commit dcc71c2

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)