summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlaok <i@blaok.me>2018-05-18 14:50:32 -0700
committerBlaok <i@blaok.me>2018-05-18 14:50:32 -0700
commit21b9ad397817af96d6d4204642debd263233bdda (patch)
tree94b15267325722463ccb0485303f94aab5a5679c
parent03a6f8e14e63a0abcf4ed8fbca12998bcbb59be3 (diff)
downloadnextcloud-server-21b9ad397817af96d6d4204642debd263233bdda.tar.gz
nextcloud-server-21b9ad397817af96d6d4204642debd263233bdda.zip
feat: allow files:scan --shallow
Signed-off-by: Yuze Chi <i@blaok.me>
-rw-r--r--apps/files/lib/Command/Scan.php11
-rw-r--r--lib/private/Files/Utils/Scanner.php4
2 files changed, 10 insertions, 5 deletions
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php
index c3b63f053f5..fed7eb25653 100644
--- a/apps/files/lib/Command/Scan.php
+++ b/apps/files/lib/Command/Scan.php
@@ -97,6 +97,11 @@ class Scan extends Base {
null,
InputOption::VALUE_NONE,
'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);
$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
@@ -158,7 +163,7 @@ class Scan extends Base {
if ($backgroundScan) {
$scanner->backgroundScan($path);
} else {
- $scanner->scan($path);
+ $scanner->scan($path, $recursive);
}
} catch (ForbiddenException $e) {
$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)");
# 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 {
$output->writeln("<error>Unknown user $user_count $user</error>");
}
diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php
index dd20e11fb63..f91696e77bb 100644
--- a/lib/private/Files/Utils/Scanner.php
+++ b/lib/private/Files/Utils/Scanner.php
@@ -185,7 +185,7 @@ class Scanner extends PublicEmitter {
* @throws \OC\ForbiddenException
* @throws \OCP\Files\NotFoundException
*/
- public function scan($dir = '') {
+ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE) {
if (!Filesystem::isValidPath($dir)) {
throw new \InvalidArgumentException('Invalid path to scan');
}
@@ -242,7 +242,7 @@ class Scanner extends PublicEmitter {
try {
$propagator = $storage->getPropagator();
$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();
if ($cache instanceof Cache) {
// only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner