Skip to content

Commit 4b3684f

Browse files
authored
Merge pull request #25943 from nextcloud/backport/25659/stable21
[stable21] catch notfound and forbidden exception in smb::getmetadata
2 parents aa8a31b + 67d62a8 commit 4b3684f

10 files changed

Lines changed: 15 additions & 25 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,13 @@ public function touch($path, $mtime = null) {
556556
}
557557

558558
public function getMetaData($path) {
559-
$fileInfo = $this->getFileInfo($path);
559+
try {
560+
$fileInfo = $this->getFileInfo($path);
561+
} catch (NotFoundException $e) {
562+
return null;
563+
} catch (ForbiddenException $e) {
564+
return null;
565+
}
560566
if (!$fileInfo) {
561567
return null;
562568
}

apps/files_sharing/lib/External/Scanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
5656
* @param int $parentId
5757
* @param array | null $cacheData existing data in the cache for the file to be scanned
5858
* @param bool $lock set to false to disable getting an additional read lock during scanning
59-
* @return array an array of metadata of the scanned file
59+
* @return array | null an array of metadata of the scanned file
6060
*/
6161
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
6262
try {

apps/files_sharing/lib/Scanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
4545
*
4646
* @param string $path path of the file for which to retrieve metadata
4747
*
48-
* @return array an array of metadata of the file
48+
* @return array|null an array of metadata of the file
4949
*/
5050
public function getData($path) {
5151
$data = parent::getData($path);

lib/private/Files/Cache/Scanner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function setUseTransactions($useTransactions) {
109109
* *
110110
*
111111
* @param string $path
112-
* @return array an array of metadata of the file
112+
* @return array|null an array of metadata of the file
113113
*/
114114
protected function getData($path) {
115115
$data = $this->storage->getMetaData($path);
@@ -128,7 +128,7 @@ protected function getData($path) {
128128
* @param array|null|false $cacheData existing data in the cache for the file to be scanned
129129
* @param bool $lock set to false to disable getting an additional read lock during scanning
130130
* @param null $data the metadata for the file, as returned by the storage
131-
* @return array an array of metadata of the scanned file
131+
* @return array|null an array of metadata of the scanned file
132132
* @throws \OCP\Lock\LockedException
133133
*/
134134
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
@@ -323,7 +323,7 @@ protected function updateCache($path, $data, $fileId = -1) {
323323
* @param bool $recursive
324324
* @param int $reuse
325325
* @param bool $lock set to false to disable getting an additional read lock during scanning
326-
* @return array an array of the meta data of the scanned file or folder
326+
* @return array|null an array of the meta data of the scanned file or folder
327327
*/
328328
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
329329
if ($reuse === -1) {

lib/private/Files/Storage/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getStorageCache();
9393

9494
/**
9595
* @param string $path
96-
* @return array
96+
* @return array|null
9797
*/
9898
public function getMetaData($path);
9999

lib/private/Files/Storage/Wrapper/Encoding.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,6 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
531531
return $result;
532532
}
533533

534-
/**
535-
* @param string $path
536-
* @return array
537-
*/
538534
public function getMetaData($path) {
539535
return $this->storage->getMetaData($this->findPathToUse($path));
540536
}

lib/private/Files/Storage/Wrapper/Encryption.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ private function modifyMetaData(string $path, array $data): array {
192192
return $data;
193193
}
194194

195-
/**
196-
* @param string $path
197-
* @return array
198-
*/
199195
public function getMetaData($path) {
200196
$data = $this->storage->getMetaData($path);
201197
if (is_null($data)) {

lib/private/Files/Storage/Wrapper/Jail.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,6 @@ public function getETag($path) {
441441
return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path));
442442
}
443443

444-
/**
445-
* @param string $path
446-
* @return array
447-
*/
448444
public function getMetaData($path) {
449445
return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path));
450446
}

lib/private/Files/Storage/Wrapper/Wrapper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,6 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
577577
return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
578578
}
579579

580-
/**
581-
* @param string $path
582-
* @return array
583-
*/
584580
public function getMetaData($path) {
585581
return $this->getWrapperStorage()->getMetaData($path);
586582
}

lib/public/Files/Cache/IScanner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface IScanner {
4545
* @param int $parentId
4646
* @param array | null $cacheData existing data in the cache for the file to be scanned
4747
* @param bool $lock set to false to disable getting an additional read lock during scanning
48-
* @return array an array of metadata of the scanned file
48+
* @return array | null an array of metadata of the scanned file
4949
* @throws \OC\ServerNotAvailableException
5050
* @throws \OCP\Lock\LockedException
5151
* @since 9.0.0
@@ -59,7 +59,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
5959
* @param bool $recursive
6060
* @param int $reuse
6161
* @param bool $lock set to false to disable getting an additional read lock during scanning
62-
* @return array an array of the meta data of the scanned file or folder
62+
* @return array | null an array of the meta data of the scanned file or folder
6363
* @since 9.0.0
6464
*/
6565
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true);

0 commit comments

Comments
 (0)