Merge pull request #2745 from nextcloud/oc_26590
[downstream] Skip local shares in bkg scan and occ files:scan (#26590)
This commit is contained in:
commit
f515c6db4a
|
@ -31,6 +31,7 @@ use OC\Files\Filesystem;
|
|||
use OC\ForbiddenException;
|
||||
use OC\Hooks\PublicEmitter;
|
||||
use OC\Lock\DBLockingProvider;
|
||||
use OCA\Files_Sharing\SharedStorage;
|
||||
use OCP\Files\Storage\IStorage;
|
||||
use OCP\Files\StorageNotAvailableException;
|
||||
use OCP\ILogger;
|
||||
|
@ -118,14 +119,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(SharedStorage::class)) {
|
||||
continue;
|
||||
}
|
||||
$storage = $mount->getStorage();
|
||||
$scanner = $storage->getScanner();
|
||||
$this->attachListener($mount);
|
||||
|
||||
|
@ -156,10 +162,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 +177,11 @@ class Scanner extends PublicEmitter {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// don't scan received local shares, these can be scanned when scanning the owner's storage
|
||||
if ($storage->instanceOfStorage(SharedStorage::class)) {
|
||||
continue;
|
||||
}
|
||||
$relativePath = $mount->getInternalPath($dir);
|
||||
$scanner = $storage->getScanner();
|
||||
$scanner->setUseTransactions(false);
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Test\Files\Utils;
|
|||
use OC\Files\Filesystem;
|
||||
use OC\Files\Mount\MountPoint;
|
||||
use OC\Files\Storage\Temporary;
|
||||
use OCA\Files_Sharing\SharedStorage;
|
||||
use OCP\Files\Config\IMountProvider;
|
||||
use OCP\Files\Storage\IStorageFactory;
|
||||
use OCP\IUser;
|
||||
|
@ -188,4 +189,24 @@ class ScannerTest extends \Test\TestCase {
|
|||
|
||||
$this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag());
|
||||
}
|
||||
|
||||
public function testSkipLocalShares() {
|
||||
$sharedStorage = $this->createMock(SharedStorage::class);
|
||||
$sharedMount = new MountPoint($sharedStorage, '/share');
|
||||
Filesystem::getMountManager()->addMount($sharedMount);
|
||||
|
||||
$sharedStorage->expects($this->any())
|
||||
->method('instanceOfStorage')
|
||||
->will($this->returnValueMap([
|
||||
[SharedStorage::class, true],
|
||||
]));
|
||||
$sharedStorage->expects($this->never())
|
||||
->method('getScanner');
|
||||
|
||||
$scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
|
||||
$scanner->addMount($sharedMount);
|
||||
$scanner->scan('');
|
||||
|
||||
$scanner->backgroundScan('');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue