-
-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5fb6e9e
Fix transfer-ownership for Group Folders
LEDfan 061a919
Fix tests
LEDfan e1505ac
Add option to transfer-ownership to move data
LEDfan 9c42e85
Prevent transferring data to user which never loggedin
LEDfan d89d987
Catch \Error in Transfer::restoreShares
LEDfan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,24 +71,32 @@ public function __construct(IEncryptionManager $manager, | |
* @param IUser $destinationUser | ||
* @param string $path | ||
* | ||
* @param OutputInterface|null $output | ||
* @param bool $move | ||
* @throws TransferOwnershipException | ||
* @throws \OC\User\NoUserException | ||
*/ | ||
public function transfer(IUser $sourceUser, | ||
IUser $destinationUser, | ||
string $path, | ||
?OutputInterface $output = null): void { | ||
?OutputInterface $output = null, | ||
bool $move = false): void { | ||
$output = $output ?? new NullOutput(); | ||
$sourceUid = $sourceUser->getUID(); | ||
$destinationUid = $destinationUser->getUID(); | ||
$sourcePath = rtrim($sourceUid . '/files/' . $path, '/'); | ||
|
||
// target user has to be ready | ||
if (!$this->encryptionManager->isReadyForUser($destinationUid)) { | ||
if ($destinationUser->getLastLogin() === 0 || !$this->encryptionManager->isReadyForUser($destinationUid)) { | ||
throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to have logged in once.", 2); | ||
} | ||
|
||
$date = date('Y-m-d H-i-s'); | ||
$finalTarget = "$destinationUid/files/transferred from $sourceUid on $date"; | ||
if ($move) { | ||
$finalTarget = "$destinationUid/files/"; | ||
} else { | ||
$date = date('Y-m-d H-i-s'); | ||
$finalTarget = "$destinationUid/files/transferred from $sourceUid on $date"; | ||
} | ||
|
||
// setup filesystem | ||
Filesystem::initMountPoints($sourceUid); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this fail in 99% of the cases? |
||
} | ||
|
||
|
||
// analyse source folder | ||
$this->analyse( | ||
$sourceUid, | ||
|
@@ -273,7 +286,7 @@ private function restoreShares(string $sourceUid, | |
} | ||
} catch (\OCP\Files\NotFoundException $e) { | ||
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>'); | ||
} catch (\Exception $e) { | ||
} catch (\Throwable $e) { | ||
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>'); | ||
} | ||
$progress->advance(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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