From 12cced3d0974bda9969d2451bde0bcea7d3a37dd Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 8 Nov 2024 17:05:36 +0100 Subject: [PATCH] fix: skip inaccessible shares in ownership transfer When transferring share ownership, the process may fail if the source node is inaccessible. This patch addresses the issue by catching the error, outputting a warning, and allowing the transfer process to continue. occ files:transfer-ownership bob admin -vvv Validating quota Analysing files of bob ... 0 [->--------------------------] < 1 sec 50.5 MiB Collecting all share information for files and folders of bob ... 1 [============================] < 1 sec 50.5 MiB In View.php line 1777: [OCP\Files\NotFoundException] File with id "222702" has not been found. Exception trace: at lib/private/Files/View.php:1777 OC\Files\View->getPath() at apps/files/lib/Service/OwnershipTransferService.php:345 OCA\Files\Service\OwnershipTransferService->{closure:OCA\Files\Service\OwnershipTransferService::collectUsersShares():343}() at n/a:n/a array_map() at apps/files/lib/Service/OwnershipTransferService.php:343 OCA\Files\Service\OwnershipTransferService->collectUsersShares() at apps/files/lib/Service/OwnershipTransferService.php:137 OCA\Files\Service\OwnershipTransferService->transfer() at apps/files/lib/Command/TransferOwnership.php:112 OCA\Files\Command\TransferOwnership->execute() at 3rdparty/symfony/console/Command/Command.php:326 Symfony\Component\Console\Command\Command->run() at 3rdparty/symfony/console/Application.php:1078 Symfony\Component\Console\Application->doRunCommand() at 3rdparty/symfony/console/Application.php:324 Symfony\Component\Console\Application->doRun() at 3rdparty/symfony/console/Application.php:175 Symfony\Component\Console\Application->run() at lib/private/Console/Application.php:187 OC\Console\Application->run() at console.php:87 require_once() at occ:11 Signed-off-by: Daniel Kesselberg --- .../lib/Service/OwnershipTransferService.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 80c61d39ef5b5..1245d845d45c7 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -340,10 +340,23 @@ private function collectUsersShares( $progress->finish(); $output->writeln(''); - return array_map(fn (IShare $share) => [ - 'share' => $share, - 'suffix' => substr(Filesystem::normalizePath($view->getPath($share->getNodeId())), strlen($normalizedPath)), - ], $shares); + $accessibleShares = []; + + foreach ($shares as $share) { + try { + $normalizedSharePath = Filesystem::normalizePath($view->getPath($share->getNodeId())); + } catch (NotFoundException $e) { + $output->writeln(sprintf('Unable to transfer share "%s" with error "%s"', $share->getId(), $e->getMessage())); + continue; + } + + $accessibleShares[] = [ + 'share' => $share, + 'suffix' => substr($normalizedSharePath, strlen($normalizedPath)), + ]; + } + + return $accessibleShares; } private function collectIncomingShares(string $sourceUid,