Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
trigger a rescan when trying to fopen a file that exists in cache but…
… not on disk

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Oct 6, 2022
commit 8cf947f0dae66649359aac190f1bcd8b5c37cd6b
9 changes: 8 additions & 1 deletion 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 Expand Up @@ -373,8 +376,12 @@ public function copy($path1, $path2) {
}

public function fopen($path, $mode) {
$sourcePath = $this->getSourcePath($path);
if (!file_exists($sourcePath) && $mode === 'r') {
return false;
}
$oldMask = umask(022);
$result = fopen($this->getSourcePath($path), $mode);
$result = @fopen($sourcePath, $mode);
umask($oldMask);
return $result;
}
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