Skip to content

Commit 27b277e

Browse files
minor fixes for get/put
Signed-off-by: Robin Appelman <[email protected]>
1 parent 868dfc5 commit 27b277e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

apps/files/lib/Command/Get.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected function configure(): void {
4343
$this
4444
->setName('files:get')
4545
->setDescription('Get the contents of a file')
46-
->addArgument('file', InputArgument::REQUIRED, "File id or path")
47-
->addArgument('output', InputArgument::OPTIONAL, "Target file to output to, defaults to STDOUT");
46+
->addArgument('file', InputArgument::REQUIRED, "Source file id or Nextcloud path")
47+
->addArgument('output', InputArgument::OPTIONAL, "Target local file to output to, defaults to STDOUT");
4848
}
4949

5050
public function execute(InputInterface $input, OutputInterface $output): int {
@@ -68,7 +68,16 @@ public function execute(InputInterface $input, OutputInterface $output): int {
6868
return 1;
6969
}
7070
$source = $node->fopen('r');
71-
$target = (!$outputName || $outputName === '-') ? STDOUT : fopen($outputName, 'w');
71+
if (!$source) {
72+
$output->writeln("<error>Failed to open $fileInput for reading</error>");
73+
return 1;
74+
}
75+
$target = ($outputName === null || $outputName === '-') ? STDOUT : fopen($outputName, 'w');
76+
if (!$target) {
77+
$output->writeln("<error>Failed to open $outputName for reading</error>");
78+
return 1;
79+
}
80+
7281
stream_copy_to_stream($source, $target);
7382
return 0;
7483
} else {

apps/files/lib/Command/Put.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ protected function configure(): void {
4747
$this
4848
->setName('files:put')
4949
->setDescription('Write contents of a file')
50-
->addArgument('input', InputArgument::REQUIRED, "Source file to write, use - to read from STDIN")
51-
->addArgument('file', InputArgument::REQUIRED, "File path to write to or fileid of existing file");
50+
->addArgument('input', InputArgument::REQUIRED, "Source local path, use - to read from STDIN")
51+
->addArgument('file', InputArgument::REQUIRED, "Target Nextcloud file path to write to or fileid of existing file");
5252
}
5353

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

68-
$source = (!$inputName || $inputName === '-') ? STDIN : fopen($inputName, 'r');
68+
$source = ($inputName === null || $inputName === '-') ? STDIN : fopen($inputName, 'r');
6969
if (!$source) {
7070
$output->writeln("<error>Failed to open $inputName</error>");
7171
return 1;
7272
}
7373
if ($node instanceof File) {
7474
$target = $node->fopen('w');
75+
if (!$target) {
76+
$output->writeln("<error>Failed to open $fileOutput</error>");
77+
return 1;
78+
}
7579
stream_copy_to_stream($source, $target);
7680
} else {
7781
$this->rootFolder->newFile($fileOutput, $source);

0 commit comments

Comments
 (0)