Compare commits

...

2 Commits

Author SHA1 Message Date
Robin Appelman
534c4d49a2 fix: raise proper error when s3 object doesn't exist
Signed-off-by: Robin Appelman <robin@icewind.nl>
2025-08-04 16:49:08 +02:00
Robin Appelman
d0c5ead510 fix: delete filecache entries when the object doesn't exist
Signed-off-by: Robin Appelman <robin@icewind.nl>
2025-08-04 16:49:01 +02:00
2 changed files with 13 additions and 4 deletions

View File

@@ -294,6 +294,8 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
case 'rb':
$stat = $this->stat($path);
if (is_array($stat)) {
$urn = $this->getURN($stat['fileid']);
$filesize = $stat['size'] ?? 0;
// Reading 0 sized files is a waste of time
if ($filesize === 0) {
@@ -301,7 +303,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
}
try {
$handle = $this->objectStore->readObject($this->getURN($stat['fileid']));
$handle = $this->objectStore->readObject($urn);
if ($handle === false) {
return false; // keep backward compatibility
}
@@ -313,16 +315,18 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
return $handle;
} catch (NotFoundException $e) {
$this->logger->error(
'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
'Could not get object ' . $urn . ' for file ' . $path,
[
'app' => 'objectstore',
'exception' => $e,
]
);
$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 $e) {
$this->logger->error(
'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
'Could not get object ' . $urn . ' for file ' . $path,
[
'app' => 'objectstore',
'exception' => $e,

View File

@@ -13,6 +13,7 @@ use Aws\S3\S3Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Utils;
use OC\Files\Stream\SeekableHttpStream;
use OCP\Files\NotFoundException;
use Psr\Http\Message\StreamInterface;
trait S3ObjectTrait {
@@ -69,7 +70,11 @@ trait S3ObjectTrait {
}
$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;
});
if (!$fh) {
throw new \Exception("Failed to read object $urn");