aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-08-16 17:17:51 +0200
committerRobin Appelman <robin@icewind.nl>2022-09-29 11:17:16 +0200
commitcb51564356e111c79224401b9067d755ac5f5c42 (patch)
tree29e0db32baff0949a22e3bd471384819c249d489 /lib
parent1de0b10751c55b26f3d9d0077e0eb404855c613c (diff)
downloadnextcloud-server-cb51564356e111c79224401b9067d755ac5f5c42.tar.gz
nextcloud-server-cb51564356e111c79224401b9067d755ac5f5c42.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Storage/Local.php9
-rw-r--r--lib/private/Files/View.php12
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php
index 2a7e30cada6..62a04292e23 100644
--- a/lib/private/Files/Storage/Local.php
+++ b/lib/private/Files/Storage/Local.php
@@ -166,6 +166,9 @@ class Local extends \OC\Files\Storage\Common {
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);
@@ -388,11 +391,15 @@ class Local extends \OC\Files\Storage\Common {
}
public function fopen($path, $mode) {
+ $sourcePath = $this->getSourcePath($path);
+ if (!file_exists($sourcePath) && $mode === 'r') {
+ return false;
+ }
$oldMask = umask($this->defUMask);
if (($mode === 'w' || $mode === 'w+') && $this->unlinkOnTruncate) {
$this->unlink($path);
}
- $result = fopen($this->getSourcePath($path), $mode);
+ $result = @fopen($sourcePath, $mode);
umask($oldMask);
return $result;
}
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index e5394e72ffe..c78517d09ef 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1001,7 +1001,17 @@ class View {
$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 (!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;
}
/**