Add option to only scan the home storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
388ea2234f
commit
b9e685236f
2 changed files with 21 additions and 6 deletions
|
@ -32,6 +32,7 @@ use Doctrine\DBAL\Connection;
|
||||||
use OC\Core\Command\Base;
|
use OC\Core\Command\Base;
|
||||||
use OC\Core\Command\InterruptedException;
|
use OC\Core\Command\InterruptedException;
|
||||||
use OC\ForbiddenException;
|
use OC\ForbiddenException;
|
||||||
|
use OCP\Files\Mount\IMountPoint;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\Files\StorageNotAvailableException;
|
use OCP\Files\StorageNotAvailableException;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
@ -102,6 +103,11 @@ class Scan extends Base {
|
||||||
null,
|
null,
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'do not scan folders recursively'
|
'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);
|
$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
|
||||||
|
@ -163,7 +169,7 @@ class Scan extends Base {
|
||||||
if ($backgroundScan) {
|
if ($backgroundScan) {
|
||||||
$scanner->backgroundScan($path);
|
$scanner->backgroundScan($path);
|
||||||
} else {
|
} else {
|
||||||
$scanner->scan($path, $recursive);
|
$scanner->scan($path, $recursive, $homeOnly ? [$this, 'filterHomeMount'] : null);
|
||||||
}
|
}
|
||||||
} 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>");
|
||||||
|
@ -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) {
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||||
$inputPath = $input->getOption('path');
|
$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)");
|
$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'), ! $input->getOption('shallow'));
|
$this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow'), $input->getOption('home-only'));
|
||||||
} else {
|
} else {
|
||||||
$output->writeln("<error>Unknown user $user_count $user</error>");
|
$output->writeln("<error>Unknown user $user_count $user</error>");
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,15 +182,20 @@ class Scanner extends PublicEmitter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $dir
|
* @param string $dir
|
||||||
* @throws \OC\ForbiddenException
|
* @param $recursive
|
||||||
* @throws \OCP\Files\NotFoundException
|
* @param callable|null $mountFilter
|
||||||
|
* @throws ForbiddenException
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE) {
|
public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE, callable $mountFilter = null) {
|
||||||
if (!Filesystem::isValidPath($dir)) {
|
if (!Filesystem::isValidPath($dir)) {
|
||||||
throw new \InvalidArgumentException('Invalid path to scan');
|
throw new \InvalidArgumentException('Invalid path to scan');
|
||||||
}
|
}
|
||||||
$mounts = $this->getMounts($dir);
|
$mounts = $this->getMounts($dir);
|
||||||
foreach ($mounts as $mount) {
|
foreach ($mounts as $mount) {
|
||||||
|
if ($mountFilter && !$mountFilter($mount)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$storage = $mount->getStorage();
|
$storage = $mount->getStorage();
|
||||||
if (is_null($storage)) {
|
if (is_null($storage)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue