diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 2a4bc650c..bd3c1a849 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -46,7 +46,9 @@ use OCP\Files\Folder; use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountManager; use OCP\Files\NotFoundException; +use OCP\Files\Storage\IStorageFactory; use OCP\Group\Events\GroupDeletedEvent; use OCP\IAppConfig; use OCP\ICacheFactory; @@ -131,6 +133,8 @@ public function register(IRegistrationContext $context): void { $c->get(LoggerInterface::class), $c->get(IUserManager::class), $c->get(IUserSession::class), + $c->get(IMountManager::class), + $c->get(IStorageFactory::class), ); $hasVersionApp = interface_exists(\OCA\Files_Versions\Versions\IVersionBackend::class); if ($hasVersionApp) { diff --git a/lib/Mount/GroupFolderStorage.php b/lib/Mount/GroupFolderStorage.php index b18ca8bac..52cd665d3 100644 --- a/lib/Mount/GroupFolderStorage.php +++ b/lib/Mount/GroupFolderStorage.php @@ -51,6 +51,10 @@ public function getOwner($path) { return false; } + public function getUser(): ?IUser { + return $this->mountOwner; + } + public function getCache($path = '', $storage = null) { if ($this->cache) { return $this->cache; diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index edada0aa9..e3440d519 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -128,7 +128,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { $aclManager = $this->aclManagerFactory->getACLManager($user, $this->getRootStorageId()); $rootRules = $aclManager->getRelevantRulesForPath($aclRootPaths); - return array_merge(...array_filter(array_map(function (array $folder) use ($user, $loader, $conflicts, $aclManager, $rootRules): ?array { + return array_filter(array_map(function (array $folder) use ($user, $loader, $conflicts, $aclManager, $rootRules): ?IMountPoint { // check for existing files in the user home and rename them if needed $originalFolderName = $folder['mount_point']; if (in_array($originalFolderName, $conflicts)) { @@ -147,7 +147,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { $userStorage->getPropagator()->propagateChange("files/$folderName", time()); } - $mount = $this->getMount( + return $this->getMount( $folder['folder_id'], '/' . $user->getUID() . '/files/' . $folder['mount_point'], $folder['permissions'], @@ -159,23 +159,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { $aclManager, $rootRules ); - if (!$mount) { - return null; - } - $trashMount = $this->getTrashMount( - $folder['folder_id'], - '/' . $user->getUID() . '/files_trashbin/groupfolders/' . $folder['folder_id'], - $folder['quota'], - $loader, - $user - ); - - return [ - $mount, - $trashMount, - ]; - - }, $folders))); + }, $folders)); } private function getCurrentUID(): ?string { @@ -265,6 +249,7 @@ public function getTrashMount( int $quota, IStorageFactory $loader, IUser $user, + ?ICacheEntry $cacheEntry = null, ): IMountPoint { $storage = $this->getRootFolder()->getStorage(); @@ -273,7 +258,7 @@ public function getTrashMount( $trashPath = $this->getRootFolder()->getInternalPath() . '/trash/' . $id; - $trashStorage = $this->getGroupFolderStorage($id, $storage, $user, $trashPath, $quota, null); + $trashStorage = $this->getGroupFolderStorage($id, $storage, $user, $trashPath, $quota, $cacheEntry); return new GroupMountPoint( $id, diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php index 4b5eb6299..a4f9ff5b2 100644 --- a/lib/Trash/TrashBackend.php +++ b/lib/Trash/TrashBackend.php @@ -20,12 +20,15 @@ use OCA\GroupFolders\Mount\MountProvider; use OCA\GroupFolders\Versions\VersionsBackend; use OCP\Constants; +use OCP\Files\FileInfo; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountManager; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\Storage\IStorage; +use OCP\Files\Storage\IStorageFactory; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -48,6 +51,8 @@ public function __construct( private LoggerInterface $logger, private IUserManager $userManager, private IUserSession $userSession, + private IMountManager $mountManager, + private IStorageFactory $storageFactory, ) { } @@ -237,11 +242,11 @@ public function moveToTrash(IStorage $storage, string $internalPath): bool { $folderId = $storage->getFolderId(); $user = $this->userSession->getUser(); - // ensure the folder exists - $this->getTrashFolder($folderId); + $owner = $storage->getUser(); - $owner = $storage->getOwner($internalPath); - $trashFolder = $this->rootFolder->get('/' . $owner . '/files_trashbin/groupfolders/' . $folderId); + $this->setupTrashFolder($folderId, $owner); + + $trashFolder = $this->rootFolder->get('/' . $owner->getUID() . '/files_trashbin/groupfolders/' . $folderId); $trashStorage = $trashFolder->getStorage(); $time = time(); $trashName = $name . '.d' . $time; @@ -361,7 +366,22 @@ private function getTrashRoot(): Folder { } } - private function getTrashFolder(int $folderId): Folder { + private function setupTrashFolder(int $folderId, ?IUser $user = null): Folder { + if ($user) { + $mountPoint = '/' . $user->getUID() . '/files_trashbin/groupfolders/' . $folderId; + $mount = $this->mountManager->find($mountPoint); + if ($mount->getMountPoint() !== $mountPoint) { + $trashMount = $this->mountProvider->getTrashMount( + $folderId, + $mountPoint, + FileInfo::SPACE_UNLIMITED, + $this->storageFactory, + $user, + ); + $this->mountManager->addMount($trashMount); + } + } + try { return $this->appFolder->get('trash/' . $folderId); } catch (NotFoundException $e) { @@ -405,7 +425,7 @@ private function getTrashForFolders(IUser $user, array $folders): array { $mountPoint = $folder['mount_point']; // ensure the trash folder exists - $this->getTrashFolder($folderId); + $this->setupTrashFolder($folderId, $user); /** @var Folder $trashFolder */ @@ -497,7 +517,7 @@ public function getTrashNodeById(IUser $user, int $fileId): ?Node { } public function cleanTrashFolder(int $folderid): void { - $trashFolder = $this->getTrashFolder($folderid); + $trashFolder = $this->setupTrashFolder($folderid); if (!($trashFolder instanceof Folder)) { return; @@ -520,7 +540,7 @@ public function expire(Expiration $expiration): array { // calculate size of trash items $sizeInTrash = 0; - $trashFolder = $this->getTrashFolder($folderId); + $trashFolder = $this->setupTrashFolder($folderId); $nodes = []; // cache foreach ($trashItems as $groupTrashItem) { $nodeName = $groupTrashItem['name'] . '.d' . $groupTrashItem['deleted_time']; @@ -580,7 +600,7 @@ private function cleanupDeletedFoldersTrash(array $existingFolders): void { $folderId = (int)$folderId; if (!isset($existingFolders[$folderId])) { $this->cleanTrashFolder($folderId); - $this->getTrashFolder($folderId)->delete(); + $this->setupTrashFolder($folderId)->delete(); } } }