From b054321fc0346b63cab8828ca5024a59dd491d3a Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 3 Jan 2022 09:12:27 +0100 Subject: [PATCH] Handle LocalServerException when scanning external shares When remoteIsOwnCloud trows LocalServerException, the storage is unavailable and instead of crashing the scanner, ignore the specific storage. Signed-off-by: Carl Schwan --- apps/files_sharing/lib/External/Scanner.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php index 54d5a33d51729..cfde56103daa9 100644 --- a/apps/files_sharing/lib/External/Scanner.php +++ b/apps/files_sharing/lib/External/Scanner.php @@ -29,6 +29,8 @@ use OCP\Files\NotFoundException; use OCP\Files\StorageInvalidException; use OCP\Files\StorageNotAvailableException; +use OCP\Http\Client\LocalServerException; +use Psr\Log\LoggerInterface; class Scanner extends \OC\Files\Cache\Scanner { /** @var \OCA\Files_Sharing\External\Storage */ @@ -36,8 +38,15 @@ class Scanner extends \OC\Files\Cache\Scanner { /** {@inheritDoc} */ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { - if (!$this->storage->remoteIsOwnCloud()) { - return parent::scan($path, $recursive, $reuse, $lock); + try { + if (!$this->storage->remoteIsOwnCloud()) { + return parent::scan($path, $recursive, $reuse, $lock); + } + } catch (LocalServerException $e) { + // Scanner doesn't have dependency injection + \OC::$server->get(LoggerInterface::class) + ->warning('Trying to scan files inside invalid external storage: ' . $this->storage->getRemote() . ' for mountpoint ' . $this->storage->getMountPoint() . ' and id ' . $this->storage->getId()); + return; } $this->scanAll();