diff options
-rw-r--r-- | lib/private/Files/Storage/Local.php | 9 | ||||
-rw-r--r-- | lib/private/Files/View.php | 12 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index d637b3d194f..990ebdc20ab 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -157,6 +157,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); @@ -373,8 +376,12 @@ 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(022); - $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 c209c8594f7..a909cf46769 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1007,7 +1007,17 @@ class View { \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; } /** |