MaxFileSizeException should reject download job (#9778)
parent
7652408829
commit
2f4b99eacd
|
@ -225,6 +225,10 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($e instanceof MaxFileSizeExceededException) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
if ($e instanceof TransportException) {
|
if ($e instanceof TransportException) {
|
||||||
// if we got an http response with a proper code, then requesting again will probably not help, abort
|
// if we got an http response with a proper code, then requesting again will probably not help, abort
|
||||||
if ((0 !== $e->getCode() && !in_array($e->getCode(), array(500, 502, 503, 504))) || !$retries) {
|
if ((0 !== $e->getCode() && !in_array($e->getCode(), array(500, 502, 503, 504))) || !$retries) {
|
||||||
|
|
|
@ -377,16 +377,7 @@ class CurlDownloader
|
||||||
$e->setResponseInfo($progress);
|
$e->setResponseInfo($progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_resource($job['headerHandle'])) {
|
$this->rejectJob($job, $e);
|
||||||
fclose($job['headerHandle']);
|
|
||||||
}
|
|
||||||
if (is_resource($job['bodyHandle'])) {
|
|
||||||
fclose($job['bodyHandle']);
|
|
||||||
}
|
|
||||||
if ($job['filename']) {
|
|
||||||
@unlink($job['filename'].'~');
|
|
||||||
}
|
|
||||||
call_user_func($job['reject'], $e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,12 +394,12 @@ class CurlDownloader
|
||||||
if (isset($this->jobs[$i]['options']['max_file_size'])) {
|
if (isset($this->jobs[$i]['options']['max_file_size'])) {
|
||||||
// Compare max_file_size with the content-length header this value will be -1 until the header is parsed
|
// Compare max_file_size with the content-length header this value will be -1 until the header is parsed
|
||||||
if ($this->jobs[$i]['options']['max_file_size'] < $progress['download_content_length']) {
|
if ($this->jobs[$i]['options']['max_file_size'] < $progress['download_content_length']) {
|
||||||
throw new MaxFileSizeExceededException('Maximum allowed download size reached. Content-length header indicates ' . $progress['download_content_length'] . ' bytes. Allowed ' . $this->jobs[$i]['options']['max_file_size'] . ' bytes');
|
$this->rejectJob($this->jobs[$i], new MaxFileSizeExceededException('Maximum allowed download size reached. Content-length header indicates ' . $progress['download_content_length'] . ' bytes. Allowed ' . $this->jobs[$i]['options']['max_file_size'] . ' bytes'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare max_file_size with the download size in bytes
|
// Compare max_file_size with the download size in bytes
|
||||||
if ($this->jobs[$i]['options']['max_file_size'] < $progress['size_download']) {
|
if ($this->jobs[$i]['options']['max_file_size'] < $progress['size_download']) {
|
||||||
throw new MaxFileSizeExceededException('Maximum allowed download size reached. Downloaded ' . $progress['size_download'] . ' of allowed ' . $this->jobs[$i]['options']['max_file_size'] . ' bytes');
|
$this->rejectJob($this->jobs[$i], new MaxFileSizeExceededException('Maximum allowed download size reached. Downloaded ' . $progress['size_download'] . ' of allowed ' . $this->jobs[$i]['options']['max_file_size'] . ' bytes'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,6 +512,20 @@ class CurlDownloader
|
||||||
return new TransportException('The "'.$job['url'].'" file could not be downloaded ('.$errorMessage.')' . $details, $response->getStatusCode());
|
return new TransportException('The "'.$job['url'].'" file could not be downloaded ('.$errorMessage.')' . $details, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function rejectJob(array $job, \Exception $e)
|
||||||
|
{
|
||||||
|
if (is_resource($job['headerHandle'])) {
|
||||||
|
fclose($job['headerHandle']);
|
||||||
|
}
|
||||||
|
if (is_resource($job['bodyHandle'])) {
|
||||||
|
fclose($job['bodyHandle']);
|
||||||
|
}
|
||||||
|
if ($job['filename']) {
|
||||||
|
@unlink($job['filename'].'~');
|
||||||
|
}
|
||||||
|
call_user_func($job['reject'], $e);
|
||||||
|
}
|
||||||
|
|
||||||
private function checkCurlResult($code)
|
private function checkCurlResult($code)
|
||||||
{
|
{
|
||||||
if ($code != CURLM_OK && $code != CURLM_CALL_MULTI_PERFORM) {
|
if ($code != CURLM_OK && $code != CURLM_CALL_MULTI_PERFORM) {
|
||||||
|
|
Loading…
Reference in New Issue