Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
minor fixes for get/put
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed May 9, 2023
commit ddc53a9046909b16d551be0bf582dbde6c32745e
15 changes: 12 additions & 3 deletions apps/files/lib/Command/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected function configure(): void {
$this
->setName('files:get')
->setDescription('Get the contents of a file')
->addArgument('file', InputArgument::REQUIRED, "File id or path")
->addArgument('output', InputArgument::OPTIONAL, "Target file to output to, defaults to STDOUT");
->addArgument('file', InputArgument::REQUIRED, "Source file id or Nextcloud path")
->addArgument('output', InputArgument::OPTIONAL, "Target local file to output to, defaults to STDOUT");
}

public function execute(InputInterface $input, OutputInterface $output): int {
Expand All @@ -68,7 +68,16 @@ public function execute(InputInterface $input, OutputInterface $output): int {
return 1;
}
$source = $node->fopen('r');
$target = (!$outputName || $outputName === '-') ? STDOUT : fopen($outputName, 'w');
if (!$source) {
$output->writeln("<error>Failed to open $fileInput for reading</error>");
return 1;
}
$target = ($outputName === null || $outputName === '-') ? STDOUT : fopen($outputName, 'w');
if (!$target) {
$output->writeln("<error>Failed to open $outputName for reading</error>");
return 1;
}

stream_copy_to_stream($source, $target);
return 0;
} else {
Expand Down
10 changes: 7 additions & 3 deletions apps/files/lib/Command/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ protected function configure(): void {
$this
->setName('files:put')
->setDescription('Write contents of a file')
->addArgument('input', InputArgument::REQUIRED, "Source file to write, use - to read from STDIN")
->addArgument('file', InputArgument::REQUIRED, "File path to write to or fileid of existing file");
->addArgument('input', InputArgument::REQUIRED, "Source local path, use - to read from STDIN")
->addArgument('file', InputArgument::REQUIRED, "Target Nextcloud file path to write to or fileid of existing file");
}

public function execute(InputInterface $input, OutputInterface $output): int {
Expand All @@ -65,13 +65,17 @@ public function execute(InputInterface $input, OutputInterface $output): int {
return 1;
}

$source = (!$inputName || $inputName === '-') ? STDIN : fopen($inputName, 'r');
$source = ($inputName === null || $inputName === '-') ? STDIN : fopen($inputName, 'r');
if (!$source) {
$output->writeln("<error>Failed to open $inputName</error>");
return 1;
}
if ($node instanceof File) {
$target = $node->fopen('w');
if (!$target) {
$output->writeln("<error>Failed to open $fileOutput</error>");
return 1;
}
stream_copy_to_stream($source, $target);
} else {
$this->rootFolder->newFile($fileOutput, $source);
Expand Down