improve file transfer code
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
f654f29532
commit
fbf3bfa3ea
|
@ -67,7 +67,7 @@ class TransferOwnership extends Command {
|
||||||
private $destinationUser;
|
private $destinationUser;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $inputPath;
|
private $sourcePath;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $finalTarget;
|
private $finalTarget;
|
||||||
|
@ -97,7 +97,8 @@ class TransferOwnership extends Command {
|
||||||
'path',
|
'path',
|
||||||
null,
|
null,
|
||||||
InputOption::VALUE_REQUIRED,
|
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->sourceUser = $sourceUserObject->getUID();
|
||||||
$this->destinationUser = $destinationUserObject->getUID();
|
$this->destinationUser = $destinationUserObject->getUID();
|
||||||
$this->inputPath = $input->getOption('path');
|
$sourcePathOption = ltrim($input->getOption('path'), '/');
|
||||||
$this->inputPath = ltrim($this->inputPath, '/');
|
$this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/');
|
||||||
|
|
||||||
// target user has to be ready
|
// target user has to be ready
|
||||||
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
|
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
|
||||||
|
@ -133,14 +134,10 @@ class TransferOwnership extends Command {
|
||||||
Filesystem::initMountPoints($this->sourceUser);
|
Filesystem::initMountPoints($this->sourceUser);
|
||||||
Filesystem::initMountPoints($this->destinationUser);
|
Filesystem::initMountPoints($this->destinationUser);
|
||||||
|
|
||||||
if (strlen($this->inputPath) >= 1) {
|
$view = new View();
|
||||||
$view = new View();
|
if (!$view->is_dir($this->sourcePath)) {
|
||||||
$unknownDir = $this->inputPath;
|
$output->writeln("<error>Unknown path provided: $sourcePathOption</error>");
|
||||||
$this->inputPath = $this->sourceUser . "/files/" . $this->inputPath;
|
return 1;
|
||||||
if (!$view->is_dir($this->inputPath)) {
|
|
||||||
$output->writeln("<error>Unknown path provided: $unknownDir</error>");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// analyse source folder
|
// analyse source folder
|
||||||
|
@ -177,14 +174,8 @@ class TransferOwnership extends Command {
|
||||||
$progress = new ProgressBar($output);
|
$progress = new ProgressBar($output);
|
||||||
$progress->start();
|
$progress->start();
|
||||||
$self = $this;
|
$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) {
|
function (FileInfo $fileInfo) use ($progress, $self) {
|
||||||
if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
|
if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
|
||||||
// only analyze into folders from main storage,
|
// only analyze into folders from main storage,
|
||||||
|
@ -245,16 +236,14 @@ class TransferOwnership extends Command {
|
||||||
protected function transfer(OutputInterface $output) {
|
protected function transfer(OutputInterface $output) {
|
||||||
$view = new View();
|
$view = new View();
|
||||||
$output->writeln("Transferring files to $this->finalTarget ...");
|
$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.
|
// 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.
|
// Else only the content inside folder is transferred which is not correct.
|
||||||
if (strlen($this->inputPath) > 0) {
|
if($this->sourcePath !== "$this->sourceUser/files") {
|
||||||
if($this->inputPath !== ltrim("$this->sourceUser/files", '/')) {
|
$view->mkdir($this->finalTarget);
|
||||||
$view->mkdir($this->finalTarget);
|
$this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath);
|
||||||
$this->finalTarget = $this->finalTarget . '/' . basename($sourcePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$view->rename($sourcePath, $this->finalTarget);
|
$view->rename($this->sourcePath, $this->finalTarget);
|
||||||
if (!is_dir("$this->sourceUser/files")) {
|
if (!is_dir("$this->sourceUser/files")) {
|
||||||
// because the files folder is moved away we need to recreate it
|
// because the files folder is moved away we need to recreate it
|
||||||
$view->mkdir("$this->sourceUser/files");
|
$view->mkdir("$this->sourceUser/files");
|
||||||
|
|
Loading…
Reference in New Issue