Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add owner fallback #49827

Open
wants to merge 5 commits into
base: stable29
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Fixed Show fixed Hide fixed
->getRelativePath($node->getPath());
}
}
Loading