Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve handling of files we can't access in the scanner #22943

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ protected function getFileInfo($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 exception 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 @@ -283,6 +285,8 @@ protected function getFolderContents($path): iterable {
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while getting folder content']);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
} catch (NotFoundException $e) {
throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e);
}
}

Expand Down Expand Up @@ -348,7 +352,7 @@ public function stat($path, $retry = true) {
$result = $this->formatInfo($this->getFileInfo($path));
} catch (ForbiddenException $e) {
return false;
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return false;
} catch (TimedOutException $e) {
if ($retry) {
Expand Down Expand Up @@ -565,7 +569,7 @@ public function touch($path, $mtime = null) {
public function getMetaData($path) {
try {
$fileInfo = $this->getFileInfo($path);
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return null;
} catch (ForbiddenException $e) {
return null;
Expand Down Expand Up @@ -641,7 +645,7 @@ public function getDirectoryContent($directory): \Traversable {
public function filetype($path) {
try {
return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file';
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return false;
} catch (ForbiddenException $e) {
return false;
Expand All @@ -665,7 +669,7 @@ public function file_exists($path) {
try {
$this->getFileInfo($path);
return true;
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return false;
} catch (ForbiddenException $e) {
return false;
Expand All @@ -678,7 +682,7 @@ public function isReadable($path) {
try {
$info = $this->getFileInfo($path);
return $this->showHidden || !$info->isHidden();
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return false;
} catch (ForbiddenException $e) {
return false;
Expand All @@ -691,7 +695,7 @@ public function isUpdatable($path) {
// following windows behaviour for read-only folders: they can be written into
// (https://support.microsoft.com/en-us/kb/326549 - "cause" section)
return ($this->showHidden || !$info->isHidden()) && (!$info->isReadOnly() || $info->isDirectory());
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return false;
} catch (ForbiddenException $e) {
return false;
Expand All @@ -702,7 +706,7 @@ public function isDeletable($path) {
try {
$info = $this->getFileInfo($path);
return ($this->showHidden || !$info->isHidden()) && !$info->isReadOnly();
} catch (NotFoundException $e) {
} catch (\OCP\Files\NotFoundException $e) {
return false;
} catch (ForbiddenException $e) {
return false;
Expand All @@ -727,6 +731,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
16 changes: 11 additions & 5 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Doctrine\DBAL\Exception;
use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IReliableEtagStorage;
use OCP\Lock\ILockingProvider;
use OC\Files\Storage\Wrapper\Encoding;
Expand Down Expand Up @@ -219,7 +220,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
$newData['parent'] = $parentId;
$data['fileid'] = $this->addToCache($file, $newData, $fileId);
}

$data['oldSize'] = ($cacheData && isset($cacheData['size'])) ? $cacheData['size'] : 0;

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