From 5ac96a4b012114d07a06770c00e3aaa819d14a8c Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 13 Jun 2022 10:15:02 +0200 Subject: [PATCH 1/3] Revert "Revert "Remove inefficient fed share scanner"" This reverts commit 6667007bf235b90a7dd105c881cf5802b2a3f83e. Signed-off-by: Carl Schwan --- apps/files_sharing/lib/External/Scanner.php | 70 ------------------- .../tests/External/ScannerTest.php | 12 ---- 2 files changed, 82 deletions(-) diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php index cfde56103daa9..009e206b959a5 100644 --- a/apps/files_sharing/lib/External/Scanner.php +++ b/apps/files_sharing/lib/External/Scanner.php @@ -29,29 +29,11 @@ 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 */ protected $storage; - /** {@inheritDoc} */ - public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { - 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(); - } - /** * Scan a single file and store it in the cache. * If an exception happened while accessing the external storage, @@ -81,56 +63,4 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = $this->storage->checkStorageAvailability(); } } - - /** - * Checks the remote share for changes. - * If changes are available, scan them and update - * the cache. - * @throws NotFoundException - * @throws StorageInvalidException - * @throws \Exception - */ - public function scanAll() { - try { - $data = $this->storage->getShareInfo(); - } catch (\Exception $e) { - $this->storage->checkStorageAvailability(); - throw new \Exception( - 'Error while scanning remote share: "' . - $this->storage->getRemote() . '" ' . - $e->getMessage() - ); - } - if ($data['status'] === 'success') { - $this->addResult($data['data'], ''); - } else { - throw new \Exception( - 'Error while scanning remote share: "' . - $this->storage->getRemote() . '"' - ); - } - } - - /** - * @param array $data - * @param string $path - */ - private function addResult($data, $path) { - $id = $this->cache->put($path, $data); - if (isset($data['children'])) { - $children = []; - foreach ($data['children'] as $child) { - $children[$child['name']] = true; - $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); - } - - $existingCache = $this->cache->getFolderContentsById($id); - foreach ($existingCache as $existingChild) { - // if an existing child is not in the new data, remove it - if (!isset($children[$existingChild['name']])) { - $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); - } - } - } - } } diff --git a/apps/files_sharing/tests/External/ScannerTest.php b/apps/files_sharing/tests/External/ScannerTest.php index 57696a697eb8e..2d2486737dc10 100644 --- a/apps/files_sharing/tests/External/ScannerTest.php +++ b/apps/files_sharing/tests/External/ScannerTest.php @@ -50,18 +50,6 @@ protected function setUp(): void { $this->scanner = new Scanner($this->storage); } - public function testScanAll() { - $this->storage->expects($this->any()) - ->method('getShareInfo') - ->willReturn(['status' => 'success', 'data' => []]); - - // FIXME add real tests, we are currently only checking for - // Declaration of OCA\Files_Sharing\External\Scanner::*() should be - // compatible with OC\Files\Cache\Scanner::*() - $this->scanner->scanAll(); - $this->addToAssertionCount(1); - } - public function testScan() { $this->storage->expects($this->any()) ->method('getShareInfo') From c0a18cbb87803befece881e7cbbaf23a8d2aba3c Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 17 Jun 2022 12:07:03 +0200 Subject: [PATCH 2/3] Disable locking on federated shares The old inneficiant code didn't do locking and adding locking is creating issues Signed-off-by: Carl Schwan --- apps/files_sharing/lib/External/Scanner.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php index 009e206b959a5..f4084ac69abf7 100644 --- a/apps/files_sharing/lib/External/Scanner.php +++ b/apps/files_sharing/lib/External/Scanner.php @@ -34,6 +34,11 @@ class Scanner extends \OC\Files\Cache\Scanner { /** @var \OCA\Files_Sharing\External\Storage */ protected $storage; + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { + // Disable locking for federated shares + parent::scan($path, $recursive, $reuse, false); + } + /** * Scan a single file and store it in the cache. * If an exception happened while accessing the external storage, From 1d66a53fab7214668c17ebfab2c262744b6a256b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 3 Aug 2022 17:12:30 +0200 Subject: [PATCH 3/3] fix external share scanner not propagating locking-opt-out Signed-off-by: Robin Appelman --- apps/files_sharing/lib/External/Scanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php index f4084ac69abf7..e3336c69a0510 100644 --- a/apps/files_sharing/lib/External/Scanner.php +++ b/apps/files_sharing/lib/External/Scanner.php @@ -54,7 +54,7 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc */ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { try { - return parent::scanFile($file, $reuseExisting); + return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock, $data); } catch (ForbiddenException $e) { $this->storage->checkStorageAvailability(); } catch (NotFoundException $e) {