diff options
author | Robin Appelman <robin@icewind.nl> | 2023-05-04 18:27:00 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-05-09 17:38:43 +0200 |
commit | ddc53a9046909b16d551be0bf582dbde6c32745e (patch) | |
tree | 8f63bd2f51b86d0ecf1dc1ecab7b8ed5e66551d2 /apps/files | |
parent | 36221a88650d5a09ffd7e1a81e9e9f62bd2a96ff (diff) | |
download | nextcloud-server-ddc53a9046909b16d551be0bf582dbde6c32745e.tar.gz nextcloud-server-ddc53a9046909b16d551be0bf582dbde6c32745e.zip |
minor fixes for get/put
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/lib/Command/Get.php | 15 | ||||
-rw-r--r-- | apps/files/lib/Command/Put.php | 10 |
2 files changed, 19 insertions, 6 deletions
diff --git a/apps/files/lib/Command/Get.php b/apps/files/lib/Command/Get.php index 29edefa1cfb..7bdb4cb59ee 100644 --- a/apps/files/lib/Command/Get.php +++ b/apps/files/lib/Command/Get.php @@ -43,8 +43,8 @@ class Get extends Command { $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 { @@ -68,7 +68,16 @@ class Get extends Command { 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 { diff --git a/apps/files/lib/Command/Put.php b/apps/files/lib/Command/Put.php index da24bbcbd00..f89ab8fb436 100644 --- a/apps/files/lib/Command/Put.php +++ b/apps/files/lib/Command/Put.php @@ -47,8 +47,8 @@ class Put extends Command { $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 { @@ -65,13 +65,17 @@ class Put extends Command { 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); |