]> source.dussan.org Git - nextcloud-server.git/commitdiff
minor fixes for get/put 38250/head
authorRobin Appelman <robin@icewind.nl>
Thu, 4 May 2023 16:27:00 +0000 (18:27 +0200)
committerRobin Appelman <robin@icewind.nl>
Wed, 6 Sep 2023 12:41:27 +0000 (14:41 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files/lib/Command/Get.php
apps/files/lib/Command/Put.php

index 29edefa1cfbaef2a7f5929c4fa849e7f3669fb83..7bdb4cb59ee2198ecbc6c31b9d996d345b9a266c 100644 (file)
@@ -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 {
index da24bbcbd00ef2a3a8475afa2c241c0f5d46bd86..f89ab8fb43607229e7a8aecb587da7c35e80d966 100644 (file)
@@ -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);