Skip to content

Commit

Permalink
fix: make user mandatory argument and use getUserFolder to get users …
Browse files Browse the repository at this point in the history
…directory. Add path to get the list based on the path or else list the user folder.

Signed-off-by: yemkareems <[email protected]>
  • Loading branch information
yemkareems committed Jul 29, 2024
1 parent bc127b5 commit a7c062b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions apps/files/lib/Command/ListFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ protected function configure(): void {
$this->setName("files:list")
->setDescription("List filesystem in the path mentioned in path argument")
->addArgument(
"path",
"user",
InputArgument::REQUIRED,
'List all the files and folder mentioned in this path, eg occ files:list path="/alice/files/Music", the path being a required argument to determine the user'
'List the files and folder belonging to the user, eg occ files:list user="admin", the user being a required argument'
)
->addOption("path", "", InputArgument::OPTIONAL, "List files inside a particular path of the user, if not mentioned list from user's root directory")
->addOption("type", "", InputArgument::OPTIONAL, "Filter by type like application, image, video etc")
->addOption(
"minSize",
Expand Down Expand Up @@ -89,17 +90,18 @@ private function getNodeInfo(Node $node): array {

protected function listFiles(
string $user,
string $path,
OutputInterface $output,
?string $path = "",
?string $type = "",
?int $minSize = 0,
?int $maxSize = 0
): void {
try {
/** @var Folder $userFolder **/
$userFolder = $this->rootFolder->get($path);
$userFolder = $this->rootFolder->getUserFolder($user);
$pathList = $userFolder->get('/'.$path);

$files = $userFolder->getDirectoryListing();
$files = $pathList->getDirectoryListing();
foreach ($files as $file) {
/** @var Node $fileNode */
$fileNode = $file;
Expand Down Expand Up @@ -151,22 +153,21 @@ protected function execute(
InputInterface $input,
OutputInterface $output
): int {
$inputPath = $input->getArgument("path");
$inputPath = ltrim($inputPath, "path=");
[, $user] = explode("/", rtrim($inputPath, "/").'/', 4);
$user = $input->getArgument("user");
$user = ltrim($user, "user=");
$path = $input->getOption("path");

$this->initTools($output);

$path = $inputPath ?: "/" . $user;

if ($this->userManager->userExists($user)) {
$output->writeln(
"Starting list for user ($user)"
);
$this->listFiles(
$user,
$path,
$output,
$path,
$input->getOption("type"),
(int) $input->getOption("minSize"),
(int) $input->getOption("maxSize")
Expand Down

0 comments on commit a7c062b

Please sign in to comment.