Skip to content

Commit

Permalink
trigger a rescan when trying to fopen a file that exists in cache but…
Browse files Browse the repository at this point in the history
… not on disk

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and backportbot-nextcloud[bot] committed Oct 3, 2022
1 parent 34a9aaf commit a2f8ddf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public function is_file($path) {
public function stat($path) {
$fullPath = $this->getSourcePath($path);
clearstatcache(true, $fullPath);
if (!file_exists($fullPath)) {
return false;
}
$statResult = @stat($fullPath);
if (PHP_INT_SIZE === 4 && $statResult && !$this->is_dir($path)) {
$filesize = $this->filesize($path);
Expand Down
12 changes: 11 additions & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,17 @@ public function fopen($path, $mode) {
\OC::$server->getLogger()->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends');
}

return $this->basicOperation('fopen', $path, $hooks, $mode);
$handle = $this->basicOperation('fopen', $path, $hooks, $mode);
if (!is_resource($handle) && $mode === 'r') {
// trying to read a file that isn't on disk, check if the cache is out of sync and rescan if needed
$mount = $this->getMount($path);
$internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
$storage = $mount->getStorage();
if ($storage->getCache()->inCache($internalPath) && !$storage->file_exists($path)) {
$this->writeUpdate($storage, $internalPath);
}
}
return $handle;
}

/**
Expand Down

0 comments on commit a2f8ddf

Please sign in to comment.