Skip to content
Open
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
6 changes: 5 additions & 1 deletion apps/files_sharing/lib/Command/DeleteOrphanShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$exists = $this->orphanHelper->fileExists($share['fileid']);
$output->writeln("<info>{$share['target']}</info> owned by <info>{$share['owner']}</info>");
if ($exists) {
$output->writeln(" file still exists but the share owner lost access to it, run <info>occ info:file {$share['fileid']}</info> for more information about the file");
if ($this->orphanHelper->isInTrashbin($share['fileid'])) {
$output->writeln(" file is in the trashbin of the share owner, run <info>occ info:file {$share['fileid']}</info> for more information about the file");
} else {
$output->writeln(" file still exists but the share owner lost access to it, run <info>occ info:file {$share['fileid']}</info> for more information about the file");
}
} else {
$output->writeln(' file no longer exists');
}
Expand Down
9 changes: 9 additions & 0 deletions apps/files_sharing/lib/OrphanHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public function fileExists(int $fileId): bool {
return $query->executeQuery()->fetchOne() !== false;
}

public function isInTrashbin(int $fileId): bool {
$query = $this->connection->getQueryBuilder();
$query->select('path')
->from('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$path = $query->executeQuery()->fetchOne();
return $path !== false && str_starts_with($path, 'files_trashbin/');
}

/**
* @return \Traversable<int, array{id: int, owner: string, fileid: int, target: string}>
*/
Expand Down
39 changes: 33 additions & 6 deletions core/Command/Info/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,23 @@ public function getFilesByUser(FileInfo $file): array {
*/
public function getNode(string $fileInput): ?Node {
if (is_numeric($fileInput)) {
$mounts = $this->userMountCache->getMountsForFileId((int)$fileInput);
if (!$mounts) {
return null;
$id = (int)$fileInput;
$mounts = $this->userMountCache->getMountsForFileId($id);
if ($mounts) {
$mount = reset($mounts);
$userFolder = $this->rootFolder->getUserFolder($mount->getUser()->getUID());
$node = $userFolder->getFirstNodeById($id);
if ($node) {
return $node;
}
// the file might live outside of the user files folder, e.g. in the trashbin or versions
$node = $userFolder->getParent()->getFirstNodeById($id);
if ($node) {
return $node;
}
}
$mount = reset($mounts);
$userFolder = $this->rootFolder->getUserFolder($mount->getUser()->getUID());
return $userFolder->getFirstNodeById((int)$fileInput);
// the file might not belong to a user at all, e.g. appdata on the root storage
return $this->getNodeFromRootMount($id);
} else {
try {
return $this->rootFolder->get($fileInput);
Expand All @@ -89,6 +99,23 @@ public function getNode(string $fileInput): ?Node {
}
}

/**
* Resolve a file id directly on the root storage, covering files that are
* not part of any user mount such as appdata.
*/
private function getNodeFromRootMount(int $id): ?Node {
$mount = $this->rootFolder->getMount('');
$storage = $mount->getStorage();
if ($storage === null) {
return null;
}
$cacheEntry = $storage->getCache()->get($id);
if ($cacheEntry === false) {
return null;
}
return $this->rootFolder->getNodeFromCacheEntryAndMount($cacheEntry, $mount);
}

public function formatPermissions(string $type, int $permissions): string {
if ($permissions == Constants::PERMISSION_ALL || ($type === 'file' && $permissions == (Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE))) {
return 'full permissions';
Expand Down
Loading