From d72cdefed309c7683efabf6af49e8cb897dede98 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 30 Jul 2024 17:26:52 +0200 Subject: [PATCH] fix: fix access to version trough shares Signed-off-by: Robin Appelman --- lib/Versions/VersionsBackend.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Versions/VersionsBackend.php b/lib/Versions/VersionsBackend.php index cb2082be8..19053eee0 100644 --- a/lib/Versions/VersionsBackend.php +++ b/lib/Versions/VersionsBackend.php @@ -23,7 +23,6 @@ namespace OCA\GroupFolders\Versions; -use Exception; use OCA\DAV\Connector\Sabre\Exception\Forbidden; use OCA\Files_Versions\Versions\IDeletableVersionBackend; use OCA\Files_Versions\Versions\IMetadataVersion; @@ -32,6 +31,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; @@ -66,13 +66,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 { @@ -323,7 +328,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();