Merge pull request #9526 from Blaok/files-scan-shallow
allow shallow (non-recursive) scan when scanning file storage
This commit is contained in:
commit
587d7cc7d2
|
@ -97,6 +97,11 @@ class Scan extends Base {
|
||||||
null,
|
null,
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'only scan files which are marked as not fully scanned'
|
'only scan files which are marked as not fully scanned'
|
||||||
|
)->addOption(
|
||||||
|
'shallow',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'do not scan folders recursively'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +114,7 @@ class Scan extends Base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false) {
|
protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true) {
|
||||||
$connection = $this->reconnectToDatabase($output);
|
$connection = $this->reconnectToDatabase($output);
|
||||||
$scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger());
|
$scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger());
|
||||||
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
|
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
|
||||||
|
@ -158,7 +163,7 @@ class Scan extends Base {
|
||||||
if ($backgroundScan) {
|
if ($backgroundScan) {
|
||||||
$scanner->backgroundScan($path);
|
$scanner->backgroundScan($path);
|
||||||
} else {
|
} else {
|
||||||
$scanner->scan($path);
|
$scanner->scan($path, $recursive);
|
||||||
}
|
}
|
||||||
} catch (ForbiddenException $e) {
|
} catch (ForbiddenException $e) {
|
||||||
$output->writeln("<error>Home storage for user $user not writable</error>");
|
$output->writeln("<error>Home storage for user $user not writable</error>");
|
||||||
|
@ -231,7 +236,7 @@ class Scan extends Base {
|
||||||
}
|
}
|
||||||
$output->writeln("Starting scan for user $user_count out of $users_total ($user)");
|
$output->writeln("Starting scan for user $user_count out of $users_total ($user)");
|
||||||
# full: printout data if $verbose was set
|
# full: printout data if $verbose was set
|
||||||
$this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'));
|
$this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow'));
|
||||||
} else {
|
} else {
|
||||||
$output->writeln("<error>Unknown user $user_count $user</error>");
|
$output->writeln("<error>Unknown user $user_count $user</error>");
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ class Scanner extends PublicEmitter {
|
||||||
* @throws \OC\ForbiddenException
|
* @throws \OC\ForbiddenException
|
||||||
* @throws \OCP\Files\NotFoundException
|
* @throws \OCP\Files\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function scan($dir = '') {
|
public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE) {
|
||||||
if (!Filesystem::isValidPath($dir)) {
|
if (!Filesystem::isValidPath($dir)) {
|
||||||
throw new \InvalidArgumentException('Invalid path to scan');
|
throw new \InvalidArgumentException('Invalid path to scan');
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ class Scanner extends PublicEmitter {
|
||||||
try {
|
try {
|
||||||
$propagator = $storage->getPropagator();
|
$propagator = $storage->getPropagator();
|
||||||
$propagator->beginBatch();
|
$propagator->beginBatch();
|
||||||
$scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
|
$scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
|
||||||
$cache = $storage->getCache();
|
$cache = $storage->getCache();
|
||||||
if ($cache instanceof Cache) {
|
if ($cache instanceof Cache) {
|
||||||
// only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner
|
// only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner
|
||||||
|
|
|
@ -209,4 +209,35 @@ class ScannerTest extends \Test\TestCase {
|
||||||
|
|
||||||
$scanner->backgroundScan('');
|
$scanner->backgroundScan('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testShallow() {
|
||||||
|
$storage = new Temporary(array());
|
||||||
|
$mount = new MountPoint($storage, '');
|
||||||
|
Filesystem::getMountManager()->addMount($mount);
|
||||||
|
$cache = $storage->getCache();
|
||||||
|
|
||||||
|
$storage->mkdir('folder');
|
||||||
|
$storage->mkdir('folder/subfolder');
|
||||||
|
$storage->file_put_contents('foo.txt', 'qwerty');
|
||||||
|
$storage->file_put_contents('folder/bar.txt', 'qwerty');
|
||||||
|
$storage->file_put_contents('folder/subfolder/foobar.txt', 'qwerty');
|
||||||
|
|
||||||
|
$scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
|
||||||
|
$scanner->addMount($mount);
|
||||||
|
|
||||||
|
$scanner->scan('', $recusive = false);
|
||||||
|
$this->assertTrue($cache->inCache('folder'));
|
||||||
|
$this->assertFalse($cache->inCache('folder/subfolder'));
|
||||||
|
$this->assertTrue($cache->inCache('foo.txt'));
|
||||||
|
$this->assertFalse($cache->inCache('folder/bar.txt'));
|
||||||
|
$this->assertFalse($cache->inCache('folder/subfolder/foobar.txt'));
|
||||||
|
|
||||||
|
$scanner->scan('folder', $recusive = false);
|
||||||
|
$this->assertTrue($cache->inCache('folder'));
|
||||||
|
$this->assertTrue($cache->inCache('folder/subfolder'));
|
||||||
|
$this->assertTrue($cache->inCache('foo.txt'));
|
||||||
|
$this->assertTrue($cache->inCache('folder/bar.txt'));
|
||||||
|
$this->assertFalse($cache->inCache('folder/subfolder/foobar.txt'));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue