diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-07-31 11:10:48 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-08-31 14:23:34 +0200 |
commit | ac2999a26a4ea8677ade7bc2b6f6d4ab968f1c36 (patch) | |
tree | 78e5a865ea257f8ffc96f95b03b130a06546113e /apps/files/lib/Service | |
parent | 5fb1d8d3bef31029e52b971b0127534fe7369fd5 (diff) | |
download | nextcloud-server-ac2999a26a4ea8677ade7bc2b6f6d4ab968f1c36.tar.gz nextcloud-server-ac2999a26a4ea8677ade7bc2b6f6d4ab968f1c36.zip |
Transfer shares of the transferred root node
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/files/lib/Service')
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 1eff02e60b5..9f3e530478d 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -37,6 +37,7 @@ use OC\Files\Filesystem; use OC\Files\View; use OCA\Files\Exception\TransferOwnershipException; use OCP\Encryption\IManager as IEncryptionManager; +use OCP\Files\Config\IUserMountCache; use OCP\Files\FileInfo; use OCP\Files\IHomeStorage; use OCP\Files\InvalidPathException; @@ -65,12 +66,17 @@ class OwnershipTransferService { /** @var IMountManager */ private $mountManager; + /** @var IUserMountCache */ + private $userMountCache; + public function __construct(IEncryptionManager $manager, IShareManager $shareManager, - IMountManager $mountManager) { + IMountManager $mountManager, + IUserMountCache $userMountCache) { $this->encryptionManager = $manager; $this->shareManager = $shareManager; $this->mountManager = $mountManager; + $this->userMountCache = $userMountCache; } /** @@ -151,7 +157,9 @@ class OwnershipTransferService { // collect all the shares $shares = $this->collectUsersShares( $sourceUid, - $output + $output, + $view, + $sourcePath ); // transfer the files @@ -236,7 +244,9 @@ class OwnershipTransferService { } private function collectUsersShares(string $sourceUid, - OutputInterface $output): array { + OutputInterface $output, + View $view, + ?string $path = null): array { $output->writeln("Collecting all share information for files and folders of $sourceUid ..."); $shares = []; @@ -249,6 +259,23 @@ class OwnershipTransferService { if (empty($sharePage)) { break; } + if ($path !== null) { + $sharePage = array_filter($sharePage, function (IShare $share) use ($view, $path) { + try { + $relativePath = $view->getPath($share->getNodeId()); + $singleFileTranfer = $view->is_file($path); + if ($singleFileTranfer) { + return Filesystem::normalizePath($relativePath) === Filesystem::normalizePath($path); + } + + return mb_strpos( + Filesystem::normalizePath($relativePath . '/', false), + Filesystem::normalizePath($path . '/', false)) === 0; + } catch (\Exception $e) { + return false; + } + }); + } $shares = array_merge($shares, $sharePage); $offset += 50; } @@ -309,6 +336,12 @@ class OwnershipTransferService { $share->setSharedBy($destinationUid); } + + // trigger refetching of the node so that the new owner and mountpoint are taken into account + // otherwise the checks on the share update will fail due to the original node not being available in the new user scope + $this->userMountCache->clear(); + $share->setNodeId($share->getNode()->getId()); + $this->shareManager->updateShare($share); } } catch (\OCP\Files\NotFoundException $e) { |