Skip to content

Commit

Permalink
fix: fix access to version trough shares
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jul 30, 2024
1 parent 9998a5d commit c3b4cef
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\Files_Versions\Versions\IVersion;
use OCA\Files_Versions\Versions\IVersionBackend;
use OCA\Files_Versions\Versions\IVersionsImporterBackend;
use OCA\GroupFolders\Mount\GroupFolderStorage;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCA\GroupFolders\Mount\MountProvider;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -66,13 +67,18 @@ public function useBackendForStorage(IStorage $storage): bool {
}

private function getFolderIdForFile(FileInfo $file): int {
$mount = $file->getMountPoint();

if (!($mount instanceof GroupMountPoint)) {
throw new Exception('Trying to get the folder id for a file not in a group folder');
$storage = $file->getStorage();
$mountPoint = $file->getMountPoint();

// getting it from the mountpoint is more efficient
if ($mountPoint instanceof GroupMountPoint) {
return $mountPoint->getFolderId();
} elseif ($storage->instanceOfStorage(GroupFolderStorage::class)) {
/** @var GroupFolderStorage $storage */
return $storage->getFolderId();
} else {
throw new \LogicException("groupfolder version backend called for non groupfolder file");
}

return $mount->getFolderId();
}

public function getVersionFolderForFile(FileInfo $file): Folder {
Expand Down Expand Up @@ -323,7 +329,7 @@ public function deleteVersion(IVersion $version): void {
return;
}

$versionsFolder = $this->getVersionsFolder($mount->getFolderId())->get((string)$sourceFile->getId());
$versionsFolder = $this->getVersionsFolder($this->getFolderIdForFile($sourceFile))->get((string)$sourceFile->getId());
/** @var Folder $versionsFolder */
$versionsFolder->get((string)$version->getRevisionId())->delete();

Expand Down

0 comments on commit c3b4cef

Please sign in to comment.