summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2021-03-04 12:33:20 +0100
committerGitHub <noreply@github.com>2021-03-04 12:33:20 +0100
commit3bbacb2f541a513f47e0744ab8a629b936a091d8 (patch)
tree093e0325df24c3dd1f8f12e259571665fb8b0f68 /apps/dav
parentcdc9a1efd9653bef34b2b66168b11f30da3085ae (diff)
parentc40228a65a74aeb959b416bb764e6582c2bd52e1 (diff)
downloadnextcloud-server-3bbacb2f541a513f47e0744ab8a629b936a091d8.tar.gz
nextcloud-server-3bbacb2f541a513f47e0744ab8a629b936a091d8.zip
Merge pull request #25881 from nextcloud/techdept/psalm/sharesplugin
Fix the SharesPlugin
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php60
1 files changed, 41 insertions, 19 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index 121d1c39ff0..677da9497d8 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -29,6 +29,9 @@
namespace OCA\DAV\Connector\Sabre;
+use OCA\DAV\Connector\Sabre\Node as DavNode;
+use OCP\Files\Folder;
+use OCP\Files\NotFoundException;
use OCP\IUserSession;
use OCP\Share\IShare;
use Sabre\DAV\PropFind;
@@ -49,29 +52,22 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
*/
private $server;
- /**
- * @var \OCP\Share\IManager
- */
+ /** @var \OCP\Share\IManager */
private $shareManager;
- /**
- * @var \Sabre\DAV\Tree
- */
+ /** @var \Sabre\DAV\Tree */
private $tree;
- /**
- * @var string
- */
+ /** @var string */
private $userId;
- /**
- * @var \OCP\Files\Folder
- */
+ /** @var \OCP\Files\Folder */
private $userFolder;
- /** @var IShare[] */
+ /** @var IShare[][] */
private $cachedShares = [];
+ /** @var string[] */
private $cachedFolders = [];
/**
@@ -112,6 +108,10 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
$this->server->on('propFind', [$this, 'handleGetProperties']);
}
+ /**
+ * @param \OCP\Files\Node $node
+ * @return IShare[]
+ */
private function getShare(\OCP\Files\Node $node): array {
$result = [];
$requestedShareTypes = [
@@ -139,7 +139,11 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
return $result;
}
- private function getSharesFolder(\OCP\Files\Folder $node): array {
+ /**
+ * @param Folder $node
+ * @return IShare[][]
+ */
+ private function getSharesFolder(Folder $node): array {
return $this->shareManager->getSharesInFolder(
$this->userId,
$node,
@@ -147,7 +151,11 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
);
}
- private function getShares(\Sabre\DAV\INode $sabreNode): array {
+ /**
+ * @param DavNode $sabreNode
+ * @return IShare[]
+ */
+ private function getShares(DavNode $sabreNode): array {
if (isset($this->cachedShares[$sabreNode->getId()])) {
$shares = $this->cachedShares[$sabreNode->getId()];
} else {
@@ -157,7 +165,11 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
}
// if we already cached the folder this file is in we know there are no shares for this file
if (array_search($parentPath, $this->cachedFolders) === false) {
- $node = $this->userFolder->get($sabreNode->getPath());
+ try {
+ $node = $this->userFolder->get($sabreNode->getPath());
+ } catch (NotFoundException $e) {
+ return [];
+ }
$shares = $this->getShare($node);
$this->cachedShares[$sabreNode->getId()] = $shares;
} else {
@@ -178,19 +190,29 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
PropFind $propFind,
\Sabre\DAV\INode $sabreNode
) {
- if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
+ if (!($sabreNode instanceof DavNode)) {
return;
}
// need prefetch ?
- if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
+ if ($sabreNode instanceof Directory
&& $propFind->getDepth() !== 0
&& (
!is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) ||
!is_null($propFind->getStatus(self::SHAREES_PROPERTYNAME))
)
) {
- $folderNode = $this->userFolder->get($sabreNode->getPath());
+ try {
+ $folderNode = $this->userFolder->get($sabreNode->getPath());
+ } catch (NotFoundException $e) {
+ // If the folder can't be properly found just return
+ return;
+ }
+
+ if (!($folderNode instanceof Folder)) {
+ // Safety check
+ return;
+ }
$this->cachedFolders[] = $sabreNode->getPath();
$childShares = $this->getSharesFolder($folderNode);