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 committed Aug 16, 2022
1 parent afb17f2 commit e64159c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/private/Files/Storage/Local.php
Expand Up @@ -161,6 +161,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 @@ -377,8 +380,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($this->defUMask);
$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
Expand Up @@ -1001,7 +1001,17 @@ public function fopen($path, $mode) {
$this->logger->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends', ['app' => 'core']);
}

return $this->basicOperation('fopen', $path, $hooks, $mode);
$handle = $this->basicOperation('fopen', $path, $hooks, $mode);
if (!$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 e64159c

Please sign in to comment.