From eca5ff31fb10c2469a8c4cebf62f9993d2fed621 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 10 Nov 2016 15:44:18 +0100 Subject: [PATCH] Skip local shares in bkg scan and occ files:scan (#26590) Local shares should only be scanned when doing it for the owner to avoid repeatedly rescanning the same shared storage over and over again for every recipient. --- lib/private/files/utils/scanner.php | 21 ++++++++++++++++----- tests/lib/files/utils/scanner.php | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php index cf85ff4c997e..e3ef5036bd81 100644 --- a/lib/private/files/utils/scanner.php +++ b/lib/private/files/utils/scanner.php @@ -117,14 +117,20 @@ protected function attachListener($mount) { public function backgroundScan($dir) { $mounts = $this->getMounts($dir); foreach ($mounts as $mount) { - if (is_null($mount->getStorage())) { + $storage = $mount->getStorage(); + if (is_null($storage)) { continue; } // don't scan the root storage - if ($mount->getStorage()->instanceOfStorage('\OC\Files\Storage\Local') && $mount->getMountPoint() === '/') { + if ($storage->instanceOfStorage('\OC\Files\Storage\Local') && $mount->getMountPoint() === '/') { continue; } - $scanner = $mount->getStorage()->getScanner(); + + // don't scan received local shares, these can be scanned when scanning the owner's storage + if ($storage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { + continue; + } + $scanner = $storage->getScanner(); $this->attachListener($mount); $scanner->backgroundScan(); } @@ -140,10 +146,10 @@ public function scan($dir = '') { } $mounts = $this->getMounts($dir); foreach ($mounts as $mount) { - if (is_null($mount->getStorage())) { + $storage = $mount->getStorage(); + if (is_null($storage)) { continue; } - $storage = $mount->getStorage(); // if the home storage isn't writable then the scanner is run as the wrong user if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and (!$storage->isCreatable('') or !$storage->isCreatable('files')) @@ -155,6 +161,11 @@ public function scan($dir = '') { } } + + // don't scan received local shares, these can be scanned when scanning the owner's storage + if ($storage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { + continue; + } $relativePath = $mount->getInternalPath($dir); $scanner = $storage->getScanner(); $scanner->setUseTransactions(false); diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index 1220c57e9628..5b234801e338 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -187,4 +187,26 @@ public function testPropagateEtag() { $this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag()); } + + public function testSkipLocalShares() { + $sharedStorage = $this->getMockBuilder('OC\Files\Storage\Shared') + ->disableOriginalConstructor() + ->getMock(); + $sharedMount = new MountPoint($sharedStorage, '/share'); + Filesystem::getMountManager()->addMount($sharedMount); + + $sharedStorage->expects($this->any()) + ->method('instanceOfStorage') + ->will($this->returnValueMap([ + ['OCA\Files_Sharing\ISharedStorage', true], + ])); + $sharedStorage->expects($this->never()) + ->method('getScanner'); + + $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); + $scanner->addMount($sharedMount); + $scanner->scan(''); + + $scanner->backgroundScan(''); + } }