Skip to content
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

Closed
wants to merge 5 commits into from
Closed

Conversation

LEDfan
Copy link
Member

@LEDfan LEDfan commented Jul 17, 2019

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.

@skjnldsv
Copy link
Member

Please rebase @LEDfan :)

Copy link
Member

@blizzz blizzz left a 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>');
Copy link
Member

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;
Copy link
Member

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

@LEDfan LEDfan force-pushed the fixes_transfer_ownership branch 2 times, most recently from 4be34f9 to 0fd8a31 Compare October 12, 2019 14:55
@skjnldsv skjnldsv requested a review from blizzz October 13, 2019 07:16
@blizzz
Copy link
Member

blizzz commented Oct 31, 2019

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.

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?

@blizzz
Copy link
Member

blizzz commented Oct 31, 2019

(ah, btw, there is no notification issued with only new commits, but no comment)

This was referenced Dec 11, 2019
@ChristophWurst
Copy link
Member

@LEDfan could you have another look, please? Since your PR we've extracted the code into a reusable service #18025 because it's not only used by the CLI command in Nextcloud 18. Thus some of the changes have to be applied there.

@ChristophWurst ChristophWurst added 0. Needs triage Pending check for reproducibility or if it fits our roadmap and removed 3. to review Waiting for reviews labels Dec 13, 2019
@ChristophWurst ChristophWurst removed this from the Nextcloud 18 milestone Dec 13, 2019
@wiswedel
Copy link
Contributor

wiswedel commented Jan 2, 2020

@LEDfan could you have another look, please? Since your PR we've extracted the code into a reusable service #18025 because it's not only used by the CLI command in Nextcloud 18. Thus some of the changes have to be applied there.

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]>
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]>
@LEDfan
Copy link
Member Author

LEDfan commented Jan 3, 2020

@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.

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.

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?

I understand. IIRC the problem with the group folders was something like:

  • assume there is a group folder GF_test shared to the everyone group. This group has some user s user1-user4
  • user2 creates a folder in GF_test
  • user2 shares this folder (in the GF) again with user3
  • try do transfer from user3 to user4

On the instance I was speaking of, this throws exceptions and fails the transfer.
I just tried to reproduce this on the current master. However, the shared folder with user3 does not appear in the home folder of user3. In the section Shared with you there is also no folder, but there is the text 1 folder. The transfer command also now works without the change.

Shared with you - Nextcloud - Chromium_1283

Maybe something has changed in NC18 regarding to re-sharing folders inside groupfolders?
So, I guess it may the safest option to remove the commit related to groupfolders.

@wiswedel
Copy link
Contributor

wiswedel commented Jan 3, 2020

So, I guess it may the safest option to remove the commit related to 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

Copy link
Member

@ChristophWurst ChristophWurst left a 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')
Copy link
Member

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

@rullzer
Copy link
Member

rullzer commented Jan 8, 2020

So, I guess it may the safest option to remove the commit related to 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

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);
Copy link
Member

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?

@ChristophWurst
Copy link
Member

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.

@ChristophWurst ChristophWurst deleted the fixes_transfer_ownership branch June 25, 2021 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap bug feature: users and groups
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants