Merge pull request #51571 from nextcloud/backport/49761/stable29

[stable29] fix: skip transfering shares that we can't find
This commit is contained in:
Andy Scherzinger 2025-04-03 10:19:39 +02:00 committed by GitHub
commit ba4dc2a223
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,6 +45,7 @@ use OCP\Files\IHomeStorage;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Share\IManager as IShareManager;
@ -365,10 +366,19 @@ class OwnershipTransferService {
$progress->finish();
$output->writeln('');
return array_map(fn (IShare $share) => [
'share' => $share,
'suffix' => substr(Filesystem::normalizePath($view->getPath($share->getNodeId())), strlen($normalizedPath)),
], $shares);
return array_values(array_filter(array_map(function (IShare $share) use ($view, $normalizedPath, $output, $sourceUid) {
try {
$nodePath = $view->getPath($share->getNodeId());
} catch (NotFoundException $e) {
$output->writeln("<error>Failed to find path for shared file {$share->getNodeId()} for user $sourceUid, skipping</error>");
return null;
}
return [
'share' => $share,
'suffix' => substr(Filesystem::normalizePath($nodePath), strlen($normalizedPath)),
];
}, $shares)));
}
private function collectIncomingShares(string $sourceUid,
@ -480,7 +490,7 @@ class OwnershipTransferService {
// Normally the ID is preserved,
// but for transferes between different storages the ID might change
$newNodeId = $share->getNode()->getId();
} catch (\OCP\Files\NotFoundException) {
} catch (NotFoundException) {
// ID has changed due to transfer between different storages
// Try to get the new ID from the target path and suffix of the share
$node = $this->rootFolder->get(Filesystem::normalizePath($targetLocation . '/' . $suffix));
@ -492,7 +502,7 @@ class OwnershipTransferService {
$this->shareManager->updateShare($share);
}
}
} catch (\OCP\Files\NotFoundException $e) {
} catch (NotFoundException $e) {
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
} catch (\Throwable $e) {
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getMessage() . ' : ' . $e->getTraceAsString() . '</error>');
@ -572,7 +582,7 @@ class OwnershipTransferService {
$this->shareManager->moveShare($share, $destinationUid);
continue;
}
} catch (\OCP\Files\NotFoundException $e) {
} catch (NotFoundException $e) {
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
} catch (\Throwable $e) {
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');