Skip to content
Closed
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: 7 additions & 3 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,23 +303,27 @@ public function fopen($path, $mode) {
case 'rb':
$stat = $this->stat($path);
if (is_array($stat)) {
$urn = $this->getURN($stat['fileid']);

// 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']));
return $this->objectStore->readObject($urn);
} catch (NotFoundException $e) {
$this->logger->logException($e, [
'app' => 'objectstore',
'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
'message' => 'Could not get object ' . $urn . ' for file ' . $path,
]);
$this->logger->warning("removing filecache entry for object that doesn't seem to exist on the object store. " . json_encode($stat));
$this->getCache()->remove((int)$stat['fileid']);
throw $e;
} catch (\Exception $ex) {
$this->logger->logException($ex, [
'app' => 'objectstore',
'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
'message' => 'Could not get object ' . $urn . ' for file ' . $path,
]);
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion lib/private/Files/ObjectStore/S3ObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Aws\S3\S3Client;
use Icewind\Streams\CallbackWrapper;
use OC\Files\Stream\SeekableHttpStream;
use OCP\Files\NotFoundException;

trait S3ObjectTrait {
/**
Expand Down Expand Up @@ -71,7 +72,11 @@ public function readObject($urn) {
];

$context = stream_context_create($opts);
return fopen($request->getUri(), 'r', false, $context);
$fh = fopen($request->getUri(), 'r', false, $context);
if (!$fh && isset($http_response_header[0]) && str_contains($http_response_header[0], '404')) {
throw new NotFoundException("object $urn not found in object store bucket " . $this->getBucket());
}
return $fh;
});
}

Expand Down