]> source.dussan.org Git - nextcloud-server.git/commitdiff
trigger a rescan when trying to fopen a file that exists in cache but not on disk 33566/head
authorRobin Appelman <robin@icewind.nl>
Tue, 16 Aug 2022 15:17:51 +0000 (17:17 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 29 Sep 2022 09:17:16 +0000 (11:17 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Storage/Local.php
lib/private/Files/View.php

index 2a7e30cada6bd89744271edcd880aa65be438e28..62a04292e2321215e87f51d407519c4808f084c3 100644 (file)
@@ -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;
        }
index e5394e72ffee7c194909c9dd4a40b632fdff33f9..c78517d09ef072abef74e8a9b097a98f95117419 100644 (file)
@@ -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;
        }
 
        /**