Skip to content

Commit 6481ccb

Browse files
susnuxcome-nc
authored andcommitted
fix(files_versions): only handle path updates when there is path
`getPathForNode` can fail with null for various reasons (e.g. no owner), in this cases we need to just skip the event handling. Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 0f40e37 commit 6481ccb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

apps/files_versions/lib/Listener/FileEventsListener.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,27 @@ public function pre_renameOrCopy_hook(Node $source, Node $target): void {
374374
return;
375375
}
376376

377-
// if we rename a movable mount point, then the versions don't have
378-
// to be renamed
377+
// if we rename a movable mount point, then the versions don't have to be renamed
379378
$oldPath = $this->getPathForNode($source);
380379
$newPath = $this->getPathForNode($target);
381-
$absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files' . $oldPath);
380+
if ($oldPath === null || $newPath === null) {
381+
return;
382+
}
383+
384+
$user = $this->userSession->getUser()?->getUID();
385+
if ($user === null) {
386+
return;
387+
}
388+
389+
$absOldPath = Filesystem::normalizePath('/' . $user . '/files' . $oldPath);
382390
$manager = Filesystem::getMountManager();
383391
$mount = $manager->find($absOldPath);
384392
$internalPath = $mount->getInternalPath($absOldPath);
385393
if ($internalPath === '' and $mount instanceof MoveableMount) {
386394
return;
387395
}
388396

389-
$view = new View(\OC_User::getUser() . '/files');
397+
$view = new View($user . '/files');
390398
if ($view->file_exists($newPath)) {
391399
Storage::store($newPath);
392400
} else {

0 commit comments

Comments
 (0)