Skip to content

Commit

Permalink
delete filecache entries when the object doesn't exist
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Nov 20, 2023
1 parent 0da05fc commit daae34e
Showing 1 changed file with 7 additions and 3 deletions.
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 @@ public function fopen($path, $mode) {
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 @@ public function fopen($path, $mode) {
} 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

0 comments on commit daae34e

Please sign in to comment.