diff options
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 6ce15098d24..0ada5ddb9c5 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -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>'); |