Skip to content

Commit

Permalink
Merge pull request #26699 from owncloud/stable9-occ-filesscan-skipshares
Browse files Browse the repository at this point in the history
[stable9] Skip local shares in bkg scan and occ files:scan (#26590)
  • Loading branch information
Vincent Petry committed Nov 25, 2016
2 parents fc7abeb + eca5ff3 commit 9a2ab51
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/private/files/utils/scanner.php
Expand Up @@ -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();
}
Expand All @@ -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'))
Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/files/utils/scanner.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 9a2ab51

Please sign in to comment.