Skip to content

Commit 71d33d9

Browse files
committed
trigger a rescan when trying to fopen a file that exists in cache but not on disk
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 1de0b10 commit 71d33d9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/private/Files/Storage/Local.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public function is_file($path) {
166166
public function stat($path) {
167167
$fullPath = $this->getSourcePath($path);
168168
clearstatcache(true, $fullPath);
169+
if (!file_exists($fullPath)) {
170+
return false;
171+
}
169172
$statResult = @stat($fullPath);
170173
if (PHP_INT_SIZE === 4 && $statResult && !$this->is_dir($path)) {
171174
$filesize = $this->filesize($path);
@@ -388,11 +391,15 @@ public function copy($path1, $path2) {
388391
}
389392

390393
public function fopen($path, $mode) {
394+
$sourcePath = $this->getSourcePath($path);
395+
if (!file_exists($sourcePath) && $mode === 'r') {
396+
return false;
397+
}
391398
$oldMask = umask($this->defUMask);
392399
if (($mode === 'w' || $mode === 'w+') && $this->unlinkOnTruncate) {
393400
$this->unlink($path);
394401
}
395-
$result = fopen($this->getSourcePath($path), $mode);
402+
$result = @fopen($sourcePath, $mode);
396403
umask($oldMask);
397404
return $result;
398405
}

lib/private/Files/View.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,17 @@ public function fopen($path, $mode) {
10011001
$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']);
10021002
}
10031003

1004-
return $this->basicOperation('fopen', $path, $hooks, $mode);
1004+
$handle = $this->basicOperation('fopen', $path, $hooks, $mode);
1005+
if (!$handle && $mode === 'r') {
1006+
// trying to read a file that isn't on disk, check if the cache is out of sync and rescan if needed
1007+
$mount = $this->getMount($path);
1008+
$internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
1009+
$storage = $mount->getStorage();
1010+
if ($storage->getCache()->inCache($internalPath) && !$storage->file_exists($path)) {
1011+
$this->writeUpdate($storage, $internalPath);
1012+
}
1013+
}
1014+
return $handle;
10051015
}
10061016

10071017
/**

0 commit comments

Comments
 (0)