-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various fixes for transfer ownership #16439
Conversation
b72154a
to
07eb517
Compare
Please rebase @LEDfan :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks ok, but two nitpicks. didn't test yet.
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getMessage() . '\n' . $e->getTraceAsString() . '</error>'); | ||
} catch (\Error $e) { | ||
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getMessage() . '\n' . $e->getTraceAsString() . '</error>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Throwable
, it covers both Exception and Error.
@@ -144,6 +154,11 @@ protected function execute(InputInterface $input, OutputInterface $output) { | |||
return 1; | |||
} | |||
|
|||
if ($input->hasArgument('move') && (!$view->is_dir($this->finalTarget) || count($view->getDirectoryContent($this->finalTarget)) > 0)) { | |||
$output->writeln("<error>Destination path does not exists or is not empty</error>"); | |||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return a different error code
4be34f9
to
0fd8a31
Compare
Can you elaborate on that? We shouldn't have direct references to code from other apps in here. Maybe we need a fix in the app, or a more general rule in this code? |
(ah, btw, there is no notification issued with only new commits, but no comment) |
Could someone please speed this up so we can start digging into nextcloud/guests#223 (which I need for a customer)? |
Because Group folders don't have owners, use the same system to check the permissions of the node. Signed-off-by: Tobia De Koninck <[email protected]>
Signed-off-by: Tobia De Koninck <[email protected]>
This will move the home folder of own user to another user. Only allowed if that other user's home folder is empty. Can be used as workaround to rename users. Signed-off-by: Tobia De Koninck <[email protected]>
Signed-off-by: Tobia De Koninck <[email protected]>
This makes the command more fault tolerant. An \Error can happen when e.g. the owner of a share is null. If we don't catch this, the restore process will stop in an unknown state. Signed-off-by: Tobia De Koninck <[email protected]>
0fd8a31
to
d89d987
Compare
@ChristophWurst @wiswedel I applied the changes to the new code and quickly tested it. I'm currently doing my master thesis, so don't have much time to thoroughly test it.
I understand. IIRC the problem with the group folders was something like:
On the instance I was speaking of, this throws exceptions and fails the transfer. Maybe something has changed in NC18 regarding to re-sharing folders inside groupfolders? |
I agree. Group folders adds a hell lot of complexity to the transfer operation. I vote for skipping group folder shares for the time being and mark that as an open issue. Better this way covering all "normal" shares than having a rushed implementation with hidden non-tested corner cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good!
@@ -99,7 +104,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { | |||
$sourceUserObject, | |||
$destinationUserObject, | |||
ltrim($input->getOption('path'), '/'), | |||
$output | |||
$output, | |||
$input->hasArgument('move') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this always returns true as the parameter exists. You can use getOption('move') !== null
Group folders should not fall in the transfer ownership transfer at all. Since the user doesn't own them ;) |
@@ -99,6 +107,11 @@ public function transfer(IUser $sourceUser, | |||
throw new TransferOwnershipException("Unknown path provided: $path", 1); | |||
} | |||
|
|||
if ($move && (!$view->is_dir($finalTarget) || count($view->getDirectoryContent($finalTarget)) > 0)) { | |||
throw new TransferOwnershipException("Destination path does not exists or is not empty", 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this fail in 99% of the cases?
As the example files are put into place?
No update in a long time and conflicts badly. Let's do this from scratch if it's still relevant. If I'm not mistaken we added some of the changes in other PRs. |
First of all this adds the
--move
option, this will move the data into the root of the target user, but only if this user doesn't have any files. This can be used as a workaround for renaming users (which is required in one setup when the UID of ldap changes).The three other commits are improvements to the transfer-ownership command. During my tests on a real instance, there was some issue with group folders and also the check to prevent to move to users who never logged in didn't work.
The last commit adds a catch for PHP errors. Sometimes the owner of a share was null, and this would stop the transfer script.
I guess it's okay to have this one PR, if not let me now and I will split it up.