Skip to content

Commit

Permalink
always use the default fs owner when storing versions
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Sep 1, 2022
1 parent b617f39 commit fbd0090
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,27 @@ public static function store($filename) {
return false;
}

[$uid, $filename] = self::getUidAndFilename($filename);
// since hook paths are always relative to the "default filesystem view"
// we always use the owner from there to get the full node
$uid = Filesystem::getView()->getOwner('');

$files_view = new View('/'.$uid .'/files');
/** @var Folder $userFolder */
$userFolder = \OC::$server->get(IRootFolder::class)->getUserFolder($uid);

$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$fileInfo = $files_view->getFileInfo($filename);
$id = $fileInfo->getId();
$nodes = \OC::$server->get(IRootFolder::class)->getUserFolder($uid)->getById($id);
foreach ($nodes as $node) {
$event = new CreateVersionEvent($node);
$eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event);
if ($event->shouldCreateVersion() === false) {
return false;
}
$file = $userFolder->get($filename);
if (!$file) {
return false;
}

// no use making versions for empty files
if ($fileInfo->getSize() === 0) {
if ($file->getSize() === 0) {
return false;
}

$event = new CreateVersionEvent($file);
$eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event);
if ($event->shouldCreateVersion() === false) {
return false;
}

Expand All @@ -214,7 +217,7 @@ public static function store($filename) {
$userManager = \OC::$server->get(IUserManager::class);
$user = $userManager->get($uid);

$versionManager->createVersion($user, $fileInfo);
$versionManager->createVersion($user, $file);
}


Expand Down

0 comments on commit fbd0090

Please sign in to comment.