diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 91113f6226c26..5588c9394fbcc 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -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; } diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 4d6ac3608df08..55626be42c571 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -33,6 +33,7 @@ use Aws\S3\S3Client; use Icewind\Streams\CallbackWrapper; use OC\Files\Stream\SeekableHttpStream; +use OCP\Files\NotFoundException; trait S3ObjectTrait { /** @@ -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; }); }