summaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-06-28 16:09:25 +0200
committerRobin Appelman <robin@icewind.nl>2018-06-28 16:09:25 +0200
commitb9e685236f7933e6b83bcbe6738ca764a6bfd820 (patch)
treebfdd0bb25c1bd8ba2ec4c0c7c866e5938a725355 /apps/files/lib
parent388ea2234f96be1fc774d4dc02b71e7d67d31910 (diff)
downloadnextcloud-server-b9e685236f7933e6b83bcbe6738ca764a6bfd820.tar.gz
nextcloud-server-b9e685236f7933e6b83bcbe6738ca764a6bfd820.zip
Add option to only scan the home storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/Command/Scan.php16
1 files changed, 13 insertions, 3 deletions
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php
index fed7eb25653..36fa39e043d 100644
--- a/apps/files/lib/Command/Scan.php
+++ b/apps/files/lib/Command/Scan.php
@@ -32,6 +32,7 @@ use Doctrine\DBAL\Connection;
use OC\Core\Command\Base;
use OC\Core\Command\InterruptedException;
use OC\ForbiddenException;
+use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
@@ -102,6 +103,11 @@ class Scan extends Base {
null,
InputOption::VALUE_NONE,
'do not scan folders recursively'
+ )->addOption(
+ 'home-only',
+ null,
+ InputOption::VALUE_NONE,
+ 'only scan the home storage, ignoring any mounted external storage or share'
);
}
@@ -114,7 +120,7 @@ class Scan extends Base {
}
}
- protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true) {
+ protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) {
$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
@@ -163,7 +169,7 @@ class Scan extends Base {
if ($backgroundScan) {
$scanner->backgroundScan($path);
} else {
- $scanner->scan($path, $recursive);
+ $scanner->scan($path, $recursive, $homeOnly ? [$this, 'filterHomeMount'] : null);
}
} catch (ForbiddenException $e) {
$output->writeln("<error>Home storage for user $user not writable</error>");
@@ -179,6 +185,10 @@ class Scan extends Base {
}
}
+ public function filterHomeMount(IMountPoint $mountPoint) {
+ // any mountpoint inside '/$user/files/'
+ return substr_count($mountPoint->getMountPoint(), '/') <= 3;
+ }
protected function execute(InputInterface $input, OutputInterface $output) {
$inputPath = $input->getOption('path');
@@ -236,7 +246,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'), ! $input->getOption('shallow'));
+ $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow'), $input->getOption('home-only'));
} else {
$output->writeln("<error>Unknown user $user_count $user</error>");
}