Merge pull request #11892 from owncloud/remove_triggerupdate

Remove triggerupdate.php & add quiet option for CLI scanner
This commit is contained in:
Thomas Müller 2014-12-10 16:17:29 +01:00
commit 80ae311329
4 changed files with 39 additions and 38 deletions

View File

@ -37,6 +37,18 @@ class Scan extends Command {
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'will rescan all files of the given user(s)'
)
->addOption(
'path',
'p',
InputArgument::OPTIONAL,
'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored'
)
->addOption(
'quiet',
'q',
InputOption::VALUE_NONE,
'suppress output'
)
->addOption(
'all',
null,
@ -45,16 +57,18 @@ class Scan extends Command {
);
}
protected function scanFiles($user, OutputInterface $output) {
protected function scanFiles($user, $path, $quiet, OutputInterface $output) {
$scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("Scanning <info>$path</info>");
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$output->writeln("Scanning <info>$path</info>");
});
if (!$quiet) {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("Scanning file <info>$path</info>");
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$output->writeln("Scanning folder <info>$path</info>");
});
}
try {
$scanner->scan('');
$scanner->scan($path);
} catch (ForbiddenException $e) {
$output->writeln("<error>Home storage for user $user not writable</error>");
$output->writeln("Make sure you're running the scan command only as the user the web server runs as");
@ -62,14 +76,21 @@ class Scan extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
if ($input->getOption('all')) {
$path = $input->getOption('path');
if ($path !== false) {
$path = '/'.trim($path, '/');
list (, $user, ) = explode('/', $path, 3);
$users = array($user);
} else if ($input->getOption('all')) {
$users = $this->userManager->search('');
} else {
$users = $input->getArgument('user_id');
}
$quiet = $input->getOption('quiet');
if (count($users) === 0) {
$output->writeln("<error>Please specify the user id to scan or \"--all\" to scan for all users</error>");
$output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>");
return;
}
@ -78,7 +99,7 @@ class Scan extends Command {
$user = $user->getUID();
}
if ($this->userManager->userExists($user)) {
$this->scanFiles($user, $output);
$this->scanFiles($user, $path, $quiet, $output);
} else {
$output->writeln("<error>Unknown user $user</error>");
}

View File

@ -1,23 +0,0 @@
<?php
require_once __DIR__ . '/../../lib/base.php';
if (OC::$CLI) {
if (count($argv) === 2) {
$file = $argv[1];
list(, $user) = explode('/', $file);
OCP\JSON::checkUserExists($user);
OC_Util::setupFS($user);
$view = new \OC\Files\View('');
/**
* @var \OC\Files\Storage\Storage $storage
*/
list($storage, $internalPath) = $view->resolvePath($file);
$watcher = $storage->getWatcher($internalPath);
$watcher->checkUpdate($internalPath);
} else {
echo "Usage: php triggerupdate.php /path/to/file\n";
}
} else {
echo "This script can be run from the command line only\n";
}

View File

@ -219,8 +219,10 @@ class Scanner extends BasicEmitter {
$reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
}
$data = $this->scanFile($path, $reuse);
$size = $this->scanChildren($path, $recursive, $reuse);
$data['size'] = $size;
if ($data !== null) {
$size = $this->scanChildren($path, $recursive, $reuse);
$data['size'] = $size;
}
return $data;
}

View File

@ -114,7 +114,7 @@ class Scanner extends PublicEmitter {
* @param string $dir
* @throws \OC\ForbiddenException
*/
public function scan($dir) {
public function scan($dir = '') {
$mounts = $this->getMounts($dir);
foreach ($mounts as $mount) {
if (is_null($mount->getStorage())) {
@ -127,11 +127,12 @@ class Scanner extends PublicEmitter {
) {
throw new ForbiddenException();
}
$relativePath = $mount->getInternalPath($dir);
$scanner = $storage->getScanner();
$scanner->setUseTransactions(false);
$this->attachListener($mount);
$this->db->beginTransaction();
$scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
$scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
$this->db->commit();
}
$this->propagator->propagateChanges(time());