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

delete filecache entries when the object doesn't exist #40522

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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 @@ -323,14 +323,16 @@
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) {
return fopen('php://memory', $mode);
}

try {
$handle = $this->objectStore->readObject($this->getURN($stat['fileid']));
$handle = $this->objectStore->readObject($urn);
if ($handle === false) {
return false; // keep backward compatibility
}
Expand All @@ -343,13 +345,15 @@
} 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']);

Check failure on line 351 in lib/private/Files/ObjectStore/ObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

lib/private/Files/ObjectStore/ObjectStoreStorage.php:351:33: InvalidArgument: Argument 1 of OC\Files\Cache\Cache::remove expects string, but int provided (see https://psalm.dev/004)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OC\Files\Cache\Cache::remove expects string, but int provided
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 GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Utils;
use OC\Files\Stream\SeekableHttpStream;
use OCP\Files\NotFoundException;
use Psr\Http\Message\StreamInterface;

trait S3ObjectTrait {
Expand Down Expand Up @@ -87,7 +88,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;
});
if (!$fh) {
throw new \Exception("Failed to read object $urn");
Expand Down
Loading