From 326f7ac857748b89909868c86350fa7259201e8b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 15 Feb 2021 17:52:11 +0100 Subject: [PATCH] catch notfound and forbidden exception in smb::getmetadata Signed-off-by: Robin Appelman --- apps/files_external/lib/Lib/Storage/SMB.php | 8 +++++++- apps/files_sharing/lib/External/Scanner.php | 2 +- apps/files_sharing/lib/Scanner.php | 2 +- lib/private/Files/Cache/Scanner.php | 6 +++--- lib/private/Files/Storage/Storage.php | 2 +- lib/private/Files/Storage/Wrapper/Encoding.php | 4 ---- lib/private/Files/Storage/Wrapper/Encryption.php | 4 ---- lib/private/Files/Storage/Wrapper/Jail.php | 4 ---- lib/private/Files/Storage/Wrapper/Wrapper.php | 4 ---- lib/public/Files/Cache/IScanner.php | 4 ++-- 10 files changed, 15 insertions(+), 25 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index ef6ecb6cc7..1b2e12c311 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -556,7 +556,13 @@ class SMB extends Common implements INotifyStorage { } public function getMetaData($path) { - $fileInfo = $this->getFileInfo($path); + try { + $fileInfo = $this->getFileInfo($path); + } catch (NotFoundException $e) { + return null; + } catch (ForbiddenException $e) { + return null; + } if (!$fileInfo) { return null; } diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php index 0051a1b76b..b73d7e874a 100644 --- a/apps/files_sharing/lib/External/Scanner.php +++ b/apps/files_sharing/lib/External/Scanner.php @@ -56,7 +56,7 @@ class Scanner extends \OC\Files\Cache\Scanner { * @param int $parentId * @param array | null $cacheData existing data in the cache for the file to be scanned * @param bool $lock set to false to disable getting an additional read lock during scanning - * @return array an array of metadata of the scanned file + * @return array | null an array of metadata of the scanned file */ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { try { diff --git a/apps/files_sharing/lib/Scanner.php b/apps/files_sharing/lib/Scanner.php index 36a412800e..95b599fe1f 100644 --- a/apps/files_sharing/lib/Scanner.php +++ b/apps/files_sharing/lib/Scanner.php @@ -45,7 +45,7 @@ class Scanner extends \OC\Files\Cache\Scanner { * * @param string $path path of the file for which to retrieve metadata * - * @return array an array of metadata of the file + * @return array|null an array of metadata of the file */ public function getData($path) { $data = parent::getData($path); diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index f895948574..5481e52bf3 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -108,7 +108,7 @@ class Scanner extends BasicEmitter implements IScanner { * * * * @param string $path - * @return array an array of metadata of the file + * @return array|null an array of metadata of the file */ protected function getData($path) { $data = $this->storage->getMetaData($path); @@ -127,7 +127,7 @@ class Scanner extends BasicEmitter implements IScanner { * @param array|null|false $cacheData existing data in the cache for the file to be scanned * @param bool $lock set to false to disable getting an additional read lock during scanning * @param null $data the metadata for the file, as returned by the storage - * @return array an array of metadata of the scanned file + * @return array|null an array of metadata of the scanned file * @throws \OCP\Lock\LockedException */ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { @@ -322,7 +322,7 @@ class Scanner extends BasicEmitter implements IScanner { * @param bool $recursive * @param int $reuse * @param bool $lock set to false to disable getting an additional read lock during scanning - * @return array an array of the meta data of the scanned file or folder + * @return array|null an array of the meta data of the scanned file or folder */ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { if ($reuse === -1) { diff --git a/lib/private/Files/Storage/Storage.php b/lib/private/Files/Storage/Storage.php index 56d997ab97..73793aa31f 100644 --- a/lib/private/Files/Storage/Storage.php +++ b/lib/private/Files/Storage/Storage.php @@ -93,7 +93,7 @@ interface Storage extends \OCP\Files\Storage { /** * @param string $path - * @return array + * @return array|null */ public function getMetaData($path); diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index a2ef1780d6..7ba2f06a5b 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -528,10 +528,6 @@ class Encoding extends Wrapper { return $result; } - /** - * @param string $path - * @return array - */ public function getMetaData($path) { return $this->storage->getMetaData($this->findPathToUse($path)); } diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 3a97764fbb..d6143dccfb 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -190,10 +190,6 @@ class Encryption extends Wrapper { return $data; } - /** - * @param string $path - * @return array - */ public function getMetaData($path) { $data = $this->storage->getMetaData($path); if (is_null($data)) { diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 449a238096..34d186ab43 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -438,10 +438,6 @@ class Jail extends Wrapper { return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path)); } - /** - * @param string $path - * @return array - */ public function getMetaData($path) { return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path)); } diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 4584bebe07..b88931a1c3 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -575,10 +575,6 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } - /** - * @param string $path - * @return array - */ public function getMetaData($path) { return $this->getWrapperStorage()->getMetaData($path); } diff --git a/lib/public/Files/Cache/IScanner.php b/lib/public/Files/Cache/IScanner.php index 3b00fa2af1..24281e2903 100644 --- a/lib/public/Files/Cache/IScanner.php +++ b/lib/public/Files/Cache/IScanner.php @@ -45,7 +45,7 @@ interface IScanner { * @param int $parentId * @param array | null $cacheData existing data in the cache for the file to be scanned * @param bool $lock set to false to disable getting an additional read lock during scanning - * @return array an array of metadata of the scanned file + * @return array | null an array of metadata of the scanned file * @throws \OC\ServerNotAvailableException * @throws \OCP\Lock\LockedException * @since 9.0.0 @@ -59,7 +59,7 @@ interface IScanner { * @param bool $recursive * @param int $reuse * @param bool $lock set to false to disable getting an additional read lock during scanning - * @return array an array of the meta data of the scanned file or folder + * @return array | null an array of the meta data of the scanned file or folder * @since 9.0.0 */ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true);