Skip to content

Commit

Permalink
improve handling of files we can't access in the scanner
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
icewind1991 committed Sep 18, 2020
1 parent c364b0c commit 6039742
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 9 additions & 1 deletion apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ protected function getFileInfo($path) {
return $this->statCache[$path];
} catch (ConnectException $e) {
$this->throwUnavailable($e);
} catch (NotFoundException $e) {
throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e);
} catch (ForbiddenException $e) {
// with php-smbclient, this exceptions is thrown when the provided password is invalid.
// Possible is also ForbiddenException with a different error code, so we check it.
if ($e->getCode() === 1) {
$this->throwUnavailable($e);
}
throw $e;
throw new \OCP\Files\ForbiddenException($e->getMessage(), false, $e);
}
}

Expand Down Expand Up @@ -271,6 +273,8 @@ protected function getFolderContents($path): iterable {
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while getting folder content']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
} catch (NotFoundException $e) {
throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e);
}
}

Expand Down Expand Up @@ -701,6 +705,10 @@ public static function checkDependencies() {
public function test() {
try {
return parent::test();
} catch (StorageAuthException $e) {
return false;
} catch (ForbiddenException $e) {
return false;
} catch (Exception $e) {
$this->logger->logException($e);
return false;
Expand Down
14 changes: 10 additions & 4 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OC\Hooks\BasicEmitter;
use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException;
use OCP\Files\NotFoundException;
use OCP\ILogger;
use OCP\Lock\ILockingProvider;

Expand Down Expand Up @@ -335,10 +336,15 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
}
}
try {
$data = $this->scanFile($path, $reuse, -1, null, $lock);
if ($data and $data['mimetype'] === 'httpd/unix-directory') {
$size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock);
$data['size'] = $size;
try {
$data = $this->scanFile($path, $reuse, -1, null, $lock);
if ($data and $data['mimetype'] === 'httpd/unix-directory') {
$size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock);
$data['size'] = $size;
}
} catch (NotFoundException $e) {
$this->removeFromCache($path);
return null;
}
} finally {
if ($lock) {
Expand Down

0 comments on commit 6039742

Please sign in to comment.