From 631c13dc1cf9e57b8f03aeee0e6eec39a3897f21 Mon Sep 17 00:00:00 2001 From: Jan Messer Date: Wed, 17 Jul 2024 00:24:07 +0200 Subject: [PATCH 1/3] changes accesslist default result from empty array to skeleton uses same skeleton as in nextcloud server sharehelper to prevent access array offset errors Signed-off-by: Jan Messer --- lib/FilesHooks.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 296f90bd3..261f7c800 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -570,11 +570,17 @@ protected function getUserPathsFromPath($path, $uidOwner) { try { $node = $this->rootFolder->getUserFolder($uidOwner)->get($path); } catch (NotFoundException $e) { - return []; + return [ + 'users' => [], + 'remotes' => [], + ]; } if (!$node instanceof Node) { - return []; + return [ + 'users' => [], + 'remotes' => [], + ]; } $accessList = $this->shareHelper->getPathsForAccessList($node); From fa1aedd594fa5f527a4a324f50e1f04782a291f7 Mon Sep 17 00:00:00 2001 From: Jan Messer Date: Mon, 22 Jul 2024 18:37:00 +0200 Subject: [PATCH 2/3] log warnings to give admins more infos about possibly miscalculated activities. Signed-off-by: Jan Messer --- lib/FilesHooks.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 261f7c800..ec955d463 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -570,6 +570,8 @@ protected function getUserPathsFromPath($path, $uidOwner) { try { $node = $this->rootFolder->getUserFolder($uidOwner)->get($path); } catch (NotFoundException $e) { + $this->logger->warning('Path "{path}" with owner "{uidOwner}" was not found', + ['path'=> $path, 'uidOwner'=>$uidOwner]); return [ 'users' => [], 'remotes' => [], @@ -577,6 +579,8 @@ protected function getUserPathsFromPath($path, $uidOwner) { } if (!$node instanceof Node) { + $this->logger->warning('Path "{path}" of "{uidOwner}" is not a valid type.', + ['path'=> $path, 'uidOwner'=>$uidOwner]); return [ 'users' => [], 'remotes' => [], From 151c6bda0675a0eb356483bb39a06e85ad2ca0f9 Mon Sep 17 00:00:00 2001 From: Jan Messer Date: Tue, 23 Jul 2024 19:49:56 +0200 Subject: [PATCH 3/3] fix access array offset which doesn't exist Successor hook fileMovePost is only processed if no error occured in fileMove hook Signed-off-by: Jan Messer --- lib/FilesHooks.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index ec955d463..16355d52a 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -234,6 +234,9 @@ public function fileMove($oldPath, $newPath) { return; } + // cache moveCase result until attributes are calculated for next stage (fileMovePost) + // moveCase has to be set as last part before return + $moveCase = $this->moveCase; if (strpos($oldDir, $newDir) === 0) { /** * a/b/c moved to a/c @@ -243,7 +246,7 @@ public function fileMove($oldPath, $newPath) { * - a/b/ shared: delete * - a/ shared: move/rename */ - $this->moveCase = 'moveUp'; + $moveCase = 'moveUp'; } elseif (strpos($newDir, $oldDir) === 0) { /** * a/b moved to a/c/b @@ -253,7 +256,7 @@ public function fileMove($oldPath, $newPath) { * - a/c/ shared: add * - a/ shared: move/rename */ - $this->moveCase = 'moveDown'; + $moveCase = 'moveDown'; } else { /** * a/b/c moved to a/d/c @@ -264,7 +267,7 @@ public function fileMove($oldPath, $newPath) { * - a/d/ shared: add * - a/ shared: move/rename */ - $this->moveCase = 'moveCross'; + $moveCase = 'moveCross'; } [$this->oldParentPath, $this->oldParentOwner, $this->oldParentId] = $this->getSourcePathAndOwner($oldDir); @@ -283,6 +286,9 @@ public function fileMove($oldPath, $newPath) { } $this->oldAccessList = $oldAccessList; + + // now its save to set moveCase + $this->moveCase = $moveCase; }