Skip to content

Commit ce2dba0

Browse files
committed
show error when trying to scan non existing path
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent a3569a1 commit ce2dba0

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

apps/files/lib/Command/Scan.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OC\Core\Command\Base;
3333
use OC\Core\Command\InterruptedException;
3434
use OC\ForbiddenException;
35+
use OCP\Files\NotFoundException;
3536
use OCP\Files\StorageNotAvailableException;
3637
use OCP\IDBConnection;
3738
use OCP\IUserManager;
@@ -131,7 +132,7 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output, $b
131132
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) {
132133
$output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")");
133134
});
134-
# count only
135+
# count only
135136
} else {
136137
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) {
137138
$this->filesCounter += 1;
@@ -146,17 +147,17 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output, $b
146147
}
147148
});
148149
}
149-
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) {
150+
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
150151
$this->checkScanWarning($path, $output);
151152
});
152-
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) {
153+
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
153154
$this->checkScanWarning($path, $output);
154155
});
155156

156157
try {
157158
if ($backgroundScan) {
158159
$scanner->backgroundScan($path);
159-
}else {
160+
} else {
160161
$scanner->scan($path);
161162
}
162163
} catch (ForbiddenException $e) {
@@ -165,6 +166,8 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output, $b
165166
} catch (InterruptedException $e) {
166167
# exit the function if ctrl-c has been pressed
167168
$output->writeln('Interrupted by user');
169+
} catch (NotFoundException $e) {
170+
$output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>');
168171
} catch (\Exception $e) {
169172
$output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>');
170173
$output->writeln('<error>' . $e->getTraceAsString() . '</error>');
@@ -194,7 +197,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
194197
$verbose = $input->getOption('verbose');
195198
$quiet = $input->getOption('quiet');
196199
# restrict the verbosity level to VERBOSITY_VERBOSE
197-
if ($output->getVerbosity()>OutputInterface::VERBOSITY_VERBOSE) {
200+
if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
198201
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
199202
}
200203
if ($quiet) {
@@ -223,7 +226,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {
223226
$user_count += 1;
224227
if ($this->userManager->userExists($user)) {
225228
# add an extra line when verbose is set to optical separate users
226-
if ($verbose) {$output->writeln(""); }
229+
if ($verbose) {
230+
$output->writeln("");
231+
}
227232
$output->writeln("Starting scan for user $user_count out of $users_total ($user)");
228233
# full: printout data if $verbose was set
229234
$this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'));
@@ -327,7 +332,7 @@ protected function formatExecTime() {
327332
* @return \OCP\IDBConnection
328333
*/
329334
protected function reconnectToDatabase(OutputInterface $output) {
330-
/** @var Connection | IDBConnection $connection*/
335+
/** @var Connection | IDBConnection $connection */
331336
$connection = \OC::$server->getDatabaseConnection();
332337
try {
333338
$connection->close();

lib/private/Files/Utils/Scanner.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OC\Hooks\PublicEmitter;
3333
use OC\Lock\DBLockingProvider;
3434
use OCA\Files_Sharing\SharedStorage;
35+
use OCP\Files\NotFoundException;
3536
use OCP\Files\Storage\IStorage;
3637
use OCP\Files\StorageNotAvailableException;
3738
use OCP\ILogger;
@@ -216,6 +217,9 @@ public function scan($dir = '') {
216217
try {
217218
$propagator = $storage->getPropagator();
218219
$propagator->beginBatch();
220+
if (!$storage->file_exists($relativePath)) {
221+
throw new NotFoundException($dir);
222+
}
219223
$scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
220224
$cache = $storage->getCache();
221225
if ($cache instanceof Cache) {

0 commit comments

Comments
 (0)