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>
This commit is contained in:
parent
b6c04b35c8
commit
24b69b2402
|
@ -404,12 +404,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
||||||
*/
|
*/
|
||||||
private function getContentLength($path) {
|
private function getContentLength($path) {
|
||||||
if (isset($this->filesCache[$path])) {
|
if (isset($this->filesCache[$path])) {
|
||||||
return $this->filesCache[$path]['ContentLength'];
|
return (int)$this->filesCache[$path]['ContentLength'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->headObject($path);
|
$result = $this->headObject($path);
|
||||||
if (isset($result['ContentLength'])) {
|
if (isset($result['ContentLength'])) {
|
||||||
return $result['ContentLength'];
|
return (int)$result['ContentLength'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -506,6 +506,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'rb':
|
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 {
|
try {
|
||||||
return $this->readObject($path);
|
return $this->readObject($path);
|
||||||
} catch (S3Exception $e) {
|
} catch (S3Exception $e) {
|
||||||
|
|
|
@ -286,6 +286,11 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
||||||
case 'rb':
|
case 'rb':
|
||||||
$stat = $this->stat($path);
|
$stat = $this->stat($path);
|
||||||
if (is_array($stat)) {
|
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 {
|
try {
|
||||||
return $this->objectStore->readObject($this->getURN($stat['fileid']));
|
return $this->objectStore->readObject($this->getURN($stat['fileid']));
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
|
|
Loading…
Reference in New Issue