From a39a5c672a7c78b5f77213235cdee727f2b26ce6 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Thu, 12 Dec 2024 15:53:11 +0100 Subject: [PATCH] fix: add owner fallback Signed-off-by: Anna Larch --- .../lib/Listener/FileEventsListener.php | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index 3273f1f9c40a4..145c572160fe5 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -384,16 +384,7 @@ private function getPathForNode(Node $node): ?string { $owner = $node->getOwner()?->getUid(); - // If no owner, extract it from the path. - // e.g. /user/files/foobar.txt - if (!$owner) { - $parts = explode('/', $node->getPath(), 4); - if (count($parts) === 4) { - $owner = $parts[1]; - } - } - - if ($owner) { + if ($owner !== null) { $path = $this->rootFolder ->getUserFolder($owner) ->getRelativePath($node->getPath()); @@ -403,6 +394,22 @@ private function getPathForNode(Node $node): ?string { } } - return null; + // If no owner, or didn't find a path for the owner, + // extract the owner name from the path and try again + // Happens when a file version is owned by a different user than the owner of + // the original file + // @see https://github.com/nextcloud/server/issues/40090 + $parts = explode('/', $node->getPath(), 4); + if (count($parts) === 4) { + $owner = $parts[1]; + } + + if ($owner === '' || $owner === null) { + return null; + } + + return $this->rootFolder + ->getUserFolder($owner) + ->getRelativePath($node->getPath()); } }