From 60397429c711608105201eec97baf59821ed1ea8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 18 Sep 2020 17:43:55 +0200 Subject: [PATCH] improve handling of files we can't access in the scanner instead of erroring, remove the items from the cache. this situation can be triggered if a user has access to a file but looses it afterwards Signed-off-by: Robin Appelman --- apps/files_external/lib/Lib/Storage/SMB.php | 10 +++++++++- lib/private/Files/Cache/Scanner.php | 14 ++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index c7e2583f08dd2..55f7f0065c4c8 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -190,13 +190,15 @@ protected function getFileInfo($path) { return $this->statCache[$path]; } catch (ConnectException $e) { $this->throwUnavailable($e); + } catch (NotFoundException $e) { + throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e); } catch (ForbiddenException $e) { // with php-smbclient, this exceptions is thrown when the provided password is invalid. // Possible is also ForbiddenException with a different error code, so we check it. if ($e->getCode() === 1) { $this->throwUnavailable($e); } - throw $e; + throw new \OCP\Files\ForbiddenException($e->getMessage(), false, $e); } } @@ -271,6 +273,8 @@ protected function getFolderContents($path): iterable { } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while getting folder content']); throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + } catch (NotFoundException $e) { + throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e); } } @@ -701,6 +705,10 @@ public static function checkDependencies() { public function test() { try { return parent::test(); + } catch (StorageAuthException $e) { + return false; + } catch (ForbiddenException $e) { + return false; } catch (Exception $e) { $this->logger->logException($e); return false; diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index f895948574baa..64c77b58970d4 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -40,6 +40,7 @@ use OC\Hooks\BasicEmitter; use OCP\Files\Cache\IScanner; use OCP\Files\ForbiddenException; +use OCP\Files\NotFoundException; use OCP\ILogger; use OCP\Lock\ILockingProvider; @@ -335,10 +336,15 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc } } try { - $data = $this->scanFile($path, $reuse, -1, null, $lock); - if ($data and $data['mimetype'] === 'httpd/unix-directory') { - $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock); - $data['size'] = $size; + try { + $data = $this->scanFile($path, $reuse, -1, null, $lock); + if ($data and $data['mimetype'] === 'httpd/unix-directory') { + $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock); + $data['size'] = $size; + } + } catch (NotFoundException $e) { + $this->removeFromCache($path); + return null; } } finally { if ($lock) {