From 0f17486c1d6d974e25ea75597bd2ca6f50e5e538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 10 Dec 2014 11:04:17 +0100 Subject: [PATCH] make path absolute --- apps/files/command/scan.php | 18 +++++++++++------- lib/private/files/cache/scanner.php | 6 ++++-- lib/private/files/utils/scanner.php | 3 ++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php index 6e4b3ee4bc..7cf401c7b5 100644 --- a/apps/files/command/scan.php +++ b/apps/files/command/scan.php @@ -41,8 +41,7 @@ class Scan extends Command { 'path', 'p', InputArgument::OPTIONAL, - 'limit rescan to this path, eg. --path="files/Music"', - '' + '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', @@ -62,10 +61,10 @@ class Scan extends Command { $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection()); if (!$quiet) { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { - $output->writeln("Scanning $path"); + $output->writeln("Scanning file $path"); }); $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { - $output->writeln("Scanning $path"); + $output->writeln("Scanning folder $path"); }); } try { @@ -77,16 +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'); } - $path = trim($input->getOption('path'), '/'); $quiet = $input->getOption('quiet'); + if (count($users) === 0) { - $output->writeln("Please specify the user id to scan or \"--all\" to scan for all users"); + $output->writeln("Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\""); return; } diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 444207518b..a5383cee10 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -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; } diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php index a0b0632857..7625e52e01 100644 --- a/lib/private/files/utils/scanner.php +++ b/lib/private/files/utils/scanner.php @@ -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($dir, \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());