diff options
author | provokateurin <kate@provokateurin.de> | 2025-06-23 08:24:13 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2025-07-01 13:11:19 +0200 |
commit | 8ca51376049952c87adae63c8d39f3394e10f35b (patch) | |
tree | 769e211988716c57a64bdc9c433bd4e827c055d1 | |
parent | 75bed6e72ee41d01021403183971b1537ac96870 (diff) | |
download | nextcloud-server-8ca51376049952c87adae63c8d39f3394e10f35b.tar.gz nextcloud-server-8ca51376049952c87adae63c8d39f3394e10f35b.zip |
fix(files): Limit transferring incoming shares to the selected path
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 055b3233bc0..de38a676c6c 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -10,12 +10,14 @@ declare(strict_types=1); namespace OCA\Files\Service; use Closure; +use Exception; use OC\Encryption\Manager as EncryptionManager; 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\File; use OCP\Files\FileInfo; use OCP\Files\IHomeStorage; use OCP\Files\InvalidPathException; @@ -159,13 +161,12 @@ class OwnershipTransferService { $sourceShares = $this->collectIncomingShares( $sourceUid, $output, - $view + $sourcePath, ); $destinationShares = $this->collectIncomingShares( $destinationUid, $output, - $view, - true + null, ); $this->transferIncomingShares( $sourceUid, @@ -334,7 +335,7 @@ class OwnershipTransferService { return mb_strpos( Filesystem::normalizePath($relativePath . '/', false), $normalizedPath . '/') === 0; - } catch (\Exception $e) { + } catch (Exception $e) { return false; } }); @@ -362,14 +363,16 @@ class OwnershipTransferService { }, $shares))); } - private function collectIncomingShares(string $sourceUid, + private function collectIncomingShares( + string $sourceUid, OutputInterface $output, - View $view, - bool $addKeys = false): array { + ?string $path, + ): array { $output->writeln("Collecting all incoming share information for files and folders of $sourceUid ..."); $shares = []; $progress = new ProgressBar($output); + $normalizedPath = Filesystem::normalizePath($path); $offset = 0; while (true) { @@ -378,14 +381,19 @@ class OwnershipTransferService { if (empty($sharePage)) { break; } - if ($addKeys) { - foreach ($sharePage as $singleShare) { - $shares[$singleShare->getNodeId()] = $singleShare; - } - } else { - foreach ($sharePage as $singleShare) { - $shares[] = $singleShare; - } + + if ($path !== null && $path !== "$sourceUid/files") { + $sharePage = array_filter($sharePage, static function (IShare $share) use ($sourceUid, $normalizedPath) { + try { + return str_starts_with(Filesystem::normalizePath($sourceUid . '/files' . $share->getTarget() . '/', false), $normalizedPath . '/'); + } catch (Exception) { + return false; + } + }); + } + + foreach ($sharePage as $share) { + $shares[$share->getNodeId()] = $share; } $offset += 50; |