diff options
author | Robin Appelman <robin@icewind.nl> | 2025-04-23 20:32:19 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-05-07 18:31:15 +0200 |
commit | 3a02d942aec375624ea4d00ec210e3d91a4a9050 (patch) | |
tree | 45caa5638ddb0e5a137cfaf4399aa780668081cf /apps | |
parent | 2c0e576a7dcab0d5d597f90b990a9cbc27b57bb1 (diff) | |
download | nextcloud-server-transfer-external-storage.tar.gz nextcloud-server-transfer-external-storage.zip |
fix: handle transfering the root of a mountpointtransfer-external-storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 886a232ffc0..b3a36ee13e5 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -426,29 +426,23 @@ class OwnershipTransferService { $view->mkdir($finalTarget); $finalTarget = $finalTarget . '/' . basename($sourcePath); } - if ($view->rename($sourcePath, $finalTarget, ['checkSubMounts' => false]) === false) { - throw new TransferOwnershipException('Could not transfer files.', 1); + $sourceInfo = $view->getFileInfo($sourcePath); + + /// handle the external storages mounted at the root, or the admin specifying an external storage with --path + if ($sourceInfo->getInternalPath() === '' && $includeExternalStorage) { + $this->moveMountContents($view, $sourcePath, $finalTarget); + } else { + if ($view->rename($sourcePath, $finalTarget, ['checkSubMounts' => false]) === false) { + throw new TransferOwnershipException('Could not transfer files.', 1); + } } if ($includeExternalStorage) { $nestedMounts = $this->mountManager->findIn($sourcePath); foreach ($nestedMounts as $mount) { - $relativePath = substr(trim($mount->getMountPoint(), '/'), strlen($sourcePath)); if ($mount->getMountProvider() === ConfigAdapter::class) { - if ($view->copy($mount->getMountPoint(), $finalTarget . $relativePath)) { - // just doing `rmdir` on the mountpoint would cause it to try and unmount the storage - // we need to empty the contents instead - $content = $view->getDirectoryContent($mount->getMountPoint()); - foreach ($content as $item) { - if ($item->getType() === FileInfo::TYPE_FOLDER) { - $view->rmdir($item->getPath()); - } else { - $view->unlink($item->getPath()); - } - } - } else { - $output->writeln("<warning>Could not copy {$mount->getMountPoint()}</warning>"); - } + $relativePath = substr(trim($mount->getMountPoint(), '/'), strlen($sourcePath)); + $this->moveMountContents($view, $mount->getMountPoint(), $finalTarget . $relativePath); } } } @@ -459,6 +453,23 @@ class OwnershipTransferService { } } + private function moveMountContents(View $rootView, string $source, string $target) { + if ($rootView->copy($source, $target)) { + // just doing `rmdir` on the mountpoint would cause it to try and unmount the storage + // we need to empty the contents instead + $content = $rootView->getDirectoryContent($source); + foreach ($content as $item) { + if ($item->getType() === FileInfo::TYPE_FOLDER) { + $rootView->rmdir($item->getPath()); + } else { + $rootView->unlink($item->getPath()); + } + } + } else { + throw new TransferOwnershipException("Could not transfer $source to $target"); + } + } + /** * @param string $targetLocation New location of the transfered node * @param array<array{share: IShare, suffix: string}> $shares previously collected share information |