Skip to content

Commit 78b4a8f

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 8916866 commit 78b4a8f

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

apps/files_sharing/lib/Repair/CleanupShareTarget.php

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

2223
/**
2324
* @psalm-type ShareInfo = array{id: string|int, share_type: string, share_with: string, file_source: string, file_target: string}
@@ -40,6 +41,7 @@ public function __construct(
4041
private readonly SetupManager $setupManager,
4142
private readonly IMountManager $mountManager,
4243
private readonly IRootFolder $rootFolder,
44+
private readonly LoggerInterface $logger,
4345
) {
4446
}
4547

@@ -62,6 +64,9 @@ public function run(IOutput $output) {
6264

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

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

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

96107
$output->advance();
97108
}

0 commit comments

Comments
 (0)