Skip to content

Commit 986a242

Browse files
icewind1991skjnldsv
authored andcommitted
improve handling of files we can't access in the scanner
instead of erroring, remove the items from the cache. this situation can be triggered if a user has access to a file but looses it afterwards Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent b585cf1 commit 986a242

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

apps/files_external/lib/Lib/Storage/SMB.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,15 @@ protected function getFileInfo($path) {
191191
return $this->statCache[$path];
192192
} catch (ConnectException $e) {
193193
$this->throwUnavailable($e);
194+
} catch (NotFoundException $e) {
195+
throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e);
194196
} catch (ForbiddenException $e) {
195197
// with php-smbclient, this exceptions is thrown when the provided password is invalid.
196198
// Possible is also ForbiddenException with a different error code, so we check it.
197199
if ($e->getCode() === 1) {
198200
$this->throwUnavailable($e);
199201
}
200-
throw $e;
202+
throw new \OCP\Files\ForbiddenException($e->getMessage(), false, $e);
201203
}
202204
}
203205

@@ -276,6 +278,8 @@ protected function getFolderContents($path): iterable {
276278
} catch (ConnectException $e) {
277279
$this->logger->logException($e, ['message' => 'Error while getting folder content']);
278280
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
281+
} catch (NotFoundException $e) {
282+
throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e);
279283
}
280284
}
281285

@@ -714,6 +718,10 @@ public static function checkDependencies() {
714718
public function test() {
715719
try {
716720
return parent::test();
721+
} catch (StorageAuthException $e) {
722+
return false;
723+
} catch (ForbiddenException $e) {
724+
return false;
717725
} catch (Exception $e) {
718726
$this->logger->logException($e);
719727
return false;

lib/private/Files/Cache/Scanner.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OC\Hooks\BasicEmitter;
4141
use OCP\Files\Cache\IScanner;
4242
use OCP\Files\ForbiddenException;
43+
use OCP\Files\NotFoundException;
4344
use OCP\ILogger;
4445
use OCP\Lock\ILockingProvider;
4546

@@ -335,10 +336,15 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
335336
}
336337
}
337338
try {
338-
$data = $this->scanFile($path, $reuse, -1, null, $lock);
339-
if ($data and $data['mimetype'] === 'httpd/unix-directory') {
340-
$size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock);
341-
$data['size'] = $size;
339+
try {
340+
$data = $this->scanFile($path, $reuse, -1, null, $lock);
341+
if ($data and $data['mimetype'] === 'httpd/unix-directory') {
342+
$size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock);
343+
$data['size'] = $size;
344+
}
345+
} catch (NotFoundException $e) {
346+
$this->removeFromCache($path);
347+
return null;
342348
}
343349
} finally {
344350
if ($lock) {

0 commit comments

Comments
 (0)