Skip to content

Commit

Permalink
Merge pull request #26600 from owncloud/stable9.1-d1c844093539a2d0bf8…
Browse files Browse the repository at this point in the history
…9fd5068e85448c11a8be9

[stable9.1] Skip local shares in bkg scan and occ files:scan (#26590)
  • Loading branch information
DeepDiver1975 committed Nov 22, 2016
2 parents d886da7 + 8d6a7b7 commit f118ac6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/private/Files/Utils/Scanner.php
Expand Up @@ -117,14 +117,19 @@ 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;
}

// 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);

Expand Down Expand Up @@ -155,10 +160,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'))
Expand All @@ -170,6 +175,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);
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/Files/Utils/ScannerTest.php
Expand Up @@ -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('');
}
}

0 comments on commit f118ac6

Please sign in to comment.