Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable19] Fix reading empty files from objectstorage #22753

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,12 @@ public function stat($path) {
*/
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;
Expand Down Expand Up @@ -506,6 +506,12 @@ public function fopen($path, $mode) {
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) {
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ public function fopen($path, $mode) {
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) {
Expand Down