Merge pull request #22753 from nextcloud/backport/22651/stable19

[stable19] Fix reading empty files from objectstorage
This commit is contained in:
Roeland Jago Douma 2020-09-10 08:45:01 +02:00 committed by GitHub
commit b5cb33ed36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -404,12 +404,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
*/
private function getContentLength($path) {
if (isset($this->filesCache[$path])) {
return $this->filesCache[$path]['ContentLength'];
return (int)$this->filesCache[$path]['ContentLength'];
}
$result = $this->headObject($path);
if (isset($result['ContentLength'])) {
return $result['ContentLength'];
return (int)$result['ContentLength'];
}
return 0;
@ -506,6 +506,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
switch ($mode) {
case 'r':
case 'rb':
// Don't try to fetch empty files
$stat = $this->stat($path);
if (is_array($stat) && isset($stat['size']) && $stat['size'] === 0) {
return fopen('php://memory', $mode);
}
try {
return $this->readObject($path);
} catch (S3Exception $e) {

View File

@ -286,6 +286,11 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
case 'rb':
$stat = $this->stat($path);
if (is_array($stat)) {
// Reading 0 sized files is a waste of time
if (isset($stat['size']) && $stat['size'] === 0) {
return fopen('php://memory', $mode);
}
try {
return $this->objectStore->readObject($this->getURN($stat['fileid']));
} catch (NotFoundException $e) {