From: Morris Jobke Date: Wed, 22 Mar 2017 23:39:08 +0000 (-0600) Subject: improve file transfer code X-Git-Tag: v12.0.0beta1~326^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fbf3bfa3ea63342411fb9a82c54ab1019200f034;p=nextcloud-server.git improve file transfer code Signed-off-by: Morris Jobke --- diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php index 559cf02742b..aa07cf9de91 100644 --- a/apps/files/lib/Command/TransferOwnership.php +++ b/apps/files/lib/Command/TransferOwnership.php @@ -67,7 +67,7 @@ class TransferOwnership extends Command { private $destinationUser; /** @var string */ - private $inputPath; + private $sourcePath; /** @var string */ private $finalTarget; @@ -97,7 +97,8 @@ class TransferOwnership extends Command { 'path', null, InputOption::VALUE_REQUIRED, - 'selectively provide the path to transfer. For example --path="folder_name"' + 'selectively provide the path to transfer. For example --path="folder_name"', + '' ); } @@ -117,8 +118,8 @@ class TransferOwnership extends Command { $this->sourceUser = $sourceUserObject->getUID(); $this->destinationUser = $destinationUserObject->getUID(); - $this->inputPath = $input->getOption('path'); - $this->inputPath = ltrim($this->inputPath, '/'); + $sourcePathOption = ltrim($input->getOption('path'), '/'); + $this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/'); // target user has to be ready if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) { @@ -133,14 +134,10 @@ class TransferOwnership extends Command { Filesystem::initMountPoints($this->sourceUser); Filesystem::initMountPoints($this->destinationUser); - if (strlen($this->inputPath) >= 1) { - $view = new View(); - $unknownDir = $this->inputPath; - $this->inputPath = $this->sourceUser . "/files/" . $this->inputPath; - if (!$view->is_dir($this->inputPath)) { - $output->writeln("Unknown path provided: $unknownDir"); - return 1; - } + $view = new View(); + if (!$view->is_dir($this->sourcePath)) { + $output->writeln("Unknown path provided: $sourcePathOption"); + return 1; } // analyse source folder @@ -177,14 +174,8 @@ class TransferOwnership extends Command { $progress = new ProgressBar($output); $progress->start(); $self = $this; - $walkPath = "$this->sourceUser/files"; - if ( strlen($this->inputPath) > 0) { - if ($this->inputPath !== "$this->sourceUser/files") { - $walkPath = $this->inputPath; - } - } - $this->walkFiles($view, $walkPath, + $this->walkFiles($view, $this->sourcePath, function (FileInfo $fileInfo) use ($progress, $self) { if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { // only analyze into folders from main storage, @@ -245,16 +236,14 @@ class TransferOwnership extends Command { protected function transfer(OutputInterface $output) { $view = new View(); $output->writeln("Transferring files to $this->finalTarget ..."); - $sourcePath = (strlen($this->inputPath) > 0) ? $this->inputPath : "$this->sourceUser/files"; + // This change will help user to transfer the folder specified using --path option. // Else only the content inside folder is transferred which is not correct. - if (strlen($this->inputPath) > 0) { - if($this->inputPath !== ltrim("$this->sourceUser/files", '/')) { - $view->mkdir($this->finalTarget); - $this->finalTarget = $this->finalTarget . '/' . basename($sourcePath); - } + if($this->sourcePath !== "$this->sourceUser/files") { + $view->mkdir($this->finalTarget); + $this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath); } - $view->rename($sourcePath, $this->finalTarget); + $view->rename($this->sourcePath, $this->finalTarget); if (!is_dir("$this->sourceUser/files")) { // because the files folder is moved away we need to recreate it $view->mkdir("$this->sourceUser/files");