mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 02:10:56 -05:00
Merge pull request #51570 from nextcloud/backport/49761/stable30
[stable30] fix: skip transfering shares that we can't find
This commit is contained in:
commit
873ed75660
1 changed files with 17 additions and 7 deletions
|
|
@ -21,6 +21,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\L10N\IFactory;
|
||||
|
|
@ -340,10 +341,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,
|
||||
|
|
@ -455,7 +465,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));
|
||||
|
|
@ -467,7 +477,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>');
|
||||
|
|
@ -547,7 +557,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>');
|
||||
|
|
|
|||
Loading…
Reference in a new issue