]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix reading empty files from objectstorage 22651/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Mon, 7 Sep 2020 18:53:56 +0000 (20:53 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 9 Sep 2020 18:45:13 +0000 (20:45 +0200)
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>
apps/files_external/lib/Lib/Storage/AmazonS3.php
lib/private/Files/ObjectStore/ObjectStoreStorage.php

index 56376661343c3b3656c22c33b8a3cdefe713cf65..0b36420430487abec59dce3ae31b4a7629b0155a 100644 (file)
@@ -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) {
index 950840301b046a07d7949a5df545581b7ea6591d..e675064eb1f74293ef4dc32462aafa4c0ad84d32 100644 (file)
@@ -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) {