]> source.dussan.org Git - nextcloud-server.git/commitdiff
Skip local shares in bkg scan and occ files:scan (#26590)
authorVincent Petry <pvince81@owncloud.com>
Thu, 10 Nov 2016 14:44:18 +0000 (15:44 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Tue, 10 Jan 2017 15:11:45 +0000 (16:11 +0100)
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
tests/lib/Files/Utils/ScannerTest.php

index d26c601be1aed3497b86036abe0c561a4c62e1bb..3794e316dfe00feb5962e6b2a86a01aec9a92807 100644 (file)
@@ -118,14 +118,19 @@ class Scanner extends PublicEmitter {
        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;
+                       }
+
+                       // don't scan received local shares, these can be scanned when scanning the owner's storage
+                       if ($storage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) {
                                continue;
                        }
-                       $storage = $mount->getStorage();
                        $scanner = $storage->getScanner();
                        $this->attachListener($mount);
 
@@ -156,10 +161,10 @@ class Scanner extends PublicEmitter {
                }
                $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'))
@@ -171,6 +176,11 @@ class Scanner extends PublicEmitter {
                                }
 
                        }
+
+                       // 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);
index 7895331d6158655aff895a3dd8e93987c8ac9c88..6d6007551ce464586d0fd900a3643b511e09359b 100644 (file)
@@ -188,4 +188,24 @@ class ScannerTest extends \Test\TestCase {
 
                $this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag());
        }
+
+       public function testSkipLocalShares() {
+               $sharedStorage = $this->createMock('OCA\Files_Sharing\SharedStorage');
+               $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('');
+       }
 }