Skip to content

Commit f309060

Browse files
committed
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 <[email protected]>
1 parent 99ee00b commit f309060

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ public function fopen($path, $mode) {
507507
switch ($mode) {
508508
case 'r':
509509
case 'rb':
510+
// Don't try to fetch empty files
511+
$stat = $this->stat($path);
512+
if (is_array($stat) && isset($stat['size']) && $stat['size'] === '0') {
513+
return fopen('php://memory', $mode);
514+
}
515+
510516
try {
511517
return $this->readObject($path);
512518
} catch (S3Exception $e) {

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ public function fopen($path, $mode) {
286286
case 'rb':
287287
$stat = $this->stat($path);
288288
if (is_array($stat)) {
289+
// Reading 0 sized files is a waste of time
290+
if (isset($stat['size']) && $stat['size'] === 0) {
291+
return fopen('php://memory', $mode);
292+
}
293+
289294
try {
290295
return $this->objectStore->readObject($this->getURN($stat['fileid']));
291296
} catch (NotFoundException $e) {

0 commit comments

Comments
 (0)