Skip to content

Commit 4f18ff9

Browse files
authored
Merge pull request #25944 from nextcloud/backport/25659/stable20
[stable20] catch notfound and forbidden exception in smb::getmetadata
2 parents 71b793f + 326f7ac commit 4f18ff9

File tree

10 files changed

+15
-25
lines changed

10 files changed

+15
-25
lines changed

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
@@ -108,7 +108,7 @@ public function setUseTransactions($useTransactions) {
108108
* *
109109
*
110110
* @param string $path
111-
* @return array an array of metadata of the file
111+
* @return array|null an array of metadata of the file
112112
*/
113113
protected function getData($path) {
114114
$data = $this->storage->getMetaData($path);
@@ -127,7 +127,7 @@ protected function getData($path) {
127127
* @param array|null|false $cacheData existing data in the cache for the file to be scanned
128128
* @param bool $lock set to false to disable getting an additional read lock during scanning
129129
* @param null $data the metadata for the file, as returned by the storage
130-
* @return array an array of metadata of the scanned file
130+
* @return array|null an array of metadata of the scanned file
131131
* @throws \OCP\Lock\LockedException
132132
*/
133133
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
@@ -322,7 +322,7 @@ protected function updateCache($path, $data, $fileId = -1) {
322322
* @param bool $recursive
323323
* @param int $reuse
324324
* @param bool $lock set to false to disable getting an additional read lock during scanning
325-
* @return array an array of the meta data of the scanned file or folder
325+
* @return array|null an array of the meta data of the scanned file or folder
326326
*/
327327
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
328328
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
@@ -528,10 +528,6 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
528528
return $result;
529529
}
530530

531-
/**
532-
* @param string $path
533-
* @return array
534-
*/
535531
public function getMetaData($path) {
536532
return $this->storage->getMetaData($this->findPathToUse($path));
537533
}

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

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

193-
/**
194-
* @param string $path
195-
* @return array
196-
*/
197193
public function getMetaData($path) {
198194
$data = $this->storage->getMetaData($path);
199195
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
@@ -438,10 +438,6 @@ public function getETag($path) {
438438
return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path));
439439
}
440440

441-
/**
442-
* @param string $path
443-
* @return array
444-
*/
445441
public function getMetaData($path) {
446442
return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path));
447443
}

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

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

578-
/**
579-
* @param string $path
580-
* @return array
581-
*/
582578
public function getMetaData($path) {
583579
return $this->getWrapperStorage()->getMetaData($path);
584580
}

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)