Skip to content
Snippets Groups Projects
Unverified Commit e7f03486 authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by GitHub
Browse files

Merge pull request #22651 from nextcloud/fix/s3/empty_files

Fix reading empty files from objectstorage
parents c104c192 bb06b6cc
No related branches found
No related tags found
No related merge requests found
......@@ -405,12 +405,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;
......@@ -507,6 +507,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) {
......
......@@ -296,6 +296,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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment