Skip to content

Commit 64ec2d0

Browse files
committed
fix: don't stop the entire share target repair on an error
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent a238620 commit 64ec2d0

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

apps/files_sharing/lib/Repair/CleanupShareTarget.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\Migration\IOutput;
2020
use OCP\Migration\IRepairStep;
2121
use OCP\Share\IShare;
22+
use Psr\Log\LoggerInterface;
2223

2324
/**
2425
* @psalm-type ShareInfo = array{id: string|int, share_type: string, share_with: string, file_source: string, file_target: string}
@@ -41,6 +42,7 @@ public function __construct(
4142
private readonly SetupManager $setupManager,
4243
private readonly IUserMountCache $userMountCache,
4344
private readonly IRootFolder $rootFolder,
45+
private readonly LoggerInterface $logger,
4446
) {
4547
}
4648

@@ -63,6 +65,9 @@ public function run(IOutput $output) {
6365

6466
foreach ($this->getProblemShares() as $shareInfo) {
6567
$recipient = $this->userManager->getExistingUser($shareInfo['share_with']);
68+
if (!$recipient->isEnabled()) {
69+
continue;
70+
}
6671

6772
// since we ordered the share by user, we can reuse the last data until we get to the next user
6873
if ($lastUser !== $recipient->getUID()) {
@@ -81,20 +86,26 @@ public function run(IOutput $output) {
8186
$absoluteNewTarget = $userFolder->getFullPath($newTarget);
8287
$targetParentNode = $this->rootFolder->get(dirname($absoluteNewTarget));
8388

84-
$absoluteNewTarget = $this->shareTargetValidator->generateUniqueTarget(
85-
(int)$shareInfo['file_source'],
86-
$absoluteNewTarget,
87-
$targetParentNode->getMountPoint(),
88-
$userMounts,
89-
);
90-
$newTarget = $userFolder->getRelativePath($absoluteNewTarget);
91-
92-
$this->moveShare((string)$shareInfo['id'], $newTarget);
93-
94-
$oldMountPoint = "/{$recipient->getUID()}/files$oldTarget/";
95-
$newMountPoint = "/{$recipient->getUID()}/files$newTarget/";
96-
$userMounts[$newMountPoint] = $userMounts[$oldMountPoint];
97-
unset($userMounts[$oldMountPoint]);
89+
try {
90+
$absoluteNewTarget = $this->shareTargetValidator->generateUniqueTarget(
91+
(int)$shareInfo['file_source'],
92+
$absoluteNewTarget,
93+
$targetParentNode->getMountPoint(),
94+
$userMounts,
95+
);
96+
$newTarget = $userFolder->getRelativePath($absoluteNewTarget);
97+
98+
$this->moveShare((string)$shareInfo['id'], $newTarget);
99+
100+
$oldMountPoint = "/{$recipient->getUID()}/files$oldTarget/";
101+
$newMountPoint = "/{$recipient->getUID()}/files$newTarget/";
102+
$userMounts[$newMountPoint] = $userMounts[$oldMountPoint];
103+
unset($userMounts[$oldMountPoint]);
104+
} catch (\Exception $e) {
105+
$msg = 'error cleaning up share target: ' . $e->getMessage();
106+
$this->logger->error($msg, ['exception' => $e, 'app' => 'files_sharing']);
107+
$output->warning($msg);
108+
}
98109

99110
$output->advance();
100111
}

0 commit comments

Comments
 (0)