diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2020-09-07 20:53:56 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-09-09 20:45:13 +0200 |
commit | bb06b6cce46df881d84f34adfd5b1c3f315bd718 (patch) | |
tree | 1a14bf3cd41c4c13fe968e994277aa595ab8ecc6 /apps/files_external/lib/Lib/Storage/AmazonS3.php | |
parent | cd563023dbceede717b22ce559f3efdf92b1da31 (diff) | |
download | nextcloud-server-bb06b6cce46df881d84f34adfd5b1c3f315bd718.tar.gz nextcloud-server-bb06b6cce46df881d84f34adfd5b1c3f315bd718.zip |
Fix reading empty files from objectstorage
Since we try to do range requests this will fail hard.
However since empty files are not that interesting to read anyways we
just read from an emptry memory stream.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_external/lib/Lib/Storage/AmazonS3.php')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/AmazonS3.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 56376661343..0b364204304 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -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) { |