Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions lib/Mount/GroupFolderStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 5 additions & 20 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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'],
Expand All @@ -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 {
Expand Down Expand Up @@ -265,6 +249,7 @@ public function getTrashMount(
int $quota,
IStorageFactory $loader,
IUser $user,
?ICacheEntry $cacheEntry = null,
): IMountPoint {

$storage = $this->getRootFolder()->getStorage();
Expand All @@ -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,
Expand Down
38 changes: 29 additions & 9 deletions lib/Trash/TrashBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +51,8 @@ public function __construct(
private LoggerInterface $logger,
private IUserManager $userManager,
private IUserSession $userSession,
private IMountManager $mountManager,
private IStorageFactory $storageFactory,
) {
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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'];
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
Loading