Skip to content

Commit 873ed75

Browse files
authored
Merge pull request #51570 from nextcloud/backport/49761/stable30
[stable30] fix: skip transfering shares that we can't find
2 parents 00465dc + 67d1668 commit 873ed75

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

apps/files/lib/Service/OwnershipTransferService.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\Files\InvalidPathException;
2222
use OCP\Files\IRootFolder;
2323
use OCP\Files\Mount\IMountManager;
24+
use OCP\Files\NotFoundException;
2425
use OCP\IUser;
2526
use OCP\IUserManager;
2627
use OCP\L10N\IFactory;
@@ -340,10 +341,19 @@ private function collectUsersShares(
340341
$progress->finish();
341342
$output->writeln('');
342343

343-
return array_map(fn (IShare $share) => [
344-
'share' => $share,
345-
'suffix' => substr(Filesystem::normalizePath($view->getPath($share->getNodeId())), strlen($normalizedPath)),
346-
], $shares);
344+
return array_values(array_filter(array_map(function (IShare $share) use ($view, $normalizedPath, $output, $sourceUid) {
345+
try {
346+
$nodePath = $view->getPath($share->getNodeId());
347+
} catch (NotFoundException $e) {
348+
$output->writeln("<error>Failed to find path for shared file {$share->getNodeId()} for user $sourceUid, skipping</error>");
349+
return null;
350+
}
351+
352+
return [
353+
'share' => $share,
354+
'suffix' => substr(Filesystem::normalizePath($nodePath), strlen($normalizedPath)),
355+
];
356+
}, $shares)));
347357
}
348358

349359
private function collectIncomingShares(string $sourceUid,
@@ -455,7 +465,7 @@ private function restoreShares(
455465
// Normally the ID is preserved,
456466
// but for transferes between different storages the ID might change
457467
$newNodeId = $share->getNode()->getId();
458-
} catch (\OCP\Files\NotFoundException) {
468+
} catch (NotFoundException) {
459469
// ID has changed due to transfer between different storages
460470
// Try to get the new ID from the target path and suffix of the share
461471
$node = $this->rootFolder->get(Filesystem::normalizePath($targetLocation . '/' . $suffix));
@@ -467,7 +477,7 @@ private function restoreShares(
467477
$this->shareManager->updateShare($share);
468478
}
469479
}
470-
} catch (\OCP\Files\NotFoundException $e) {
480+
} catch (NotFoundException $e) {
471481
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
472482
} catch (\Throwable $e) {
473483
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getMessage() . ' : ' . $e->getTraceAsString() . '</error>');
@@ -547,7 +557,7 @@ private function transferIncomingShares(string $sourceUid,
547557
$this->shareManager->moveShare($share, $destinationUid);
548558
continue;
549559
}
550-
} catch (\OCP\Files\NotFoundException $e) {
560+
} catch (NotFoundException $e) {
551561
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
552562
} catch (\Throwable $e) {
553563
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');

0 commit comments

Comments
 (0)