Skip to content

Commit

Permalink
fix: add owner fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <[email protected]>
  • Loading branch information
miaulalala committed Dec 17, 2024
1 parent 4f74901 commit a39a5c6
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions apps/files_versions/lib/Listener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}
}

0 comments on commit a39a5c6

Please sign in to comment.