Skip to content

Commit 28850d4

Browse files
Vincent Petryelie195
authored andcommitted
Skip broken shares when transferring ownership (owncloud#26527)
1 parent 2a48925 commit 28850d4

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

apps/files/lib/Command/TransferOwnership.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,28 @@ private function restoreShares(OutputInterface $output) {
225225
$progress = new ProgressBar($output, count($this->shares));
226226

227227
foreach($this->shares as $share) {
228-
if ($share->getSharedWith() === $this->destinationUser) {
229-
// Unmount the shares before deleting, so we don't try to get the storage later on.
230-
$shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
231-
if ($shareMountPoint) {
232-
$this->mountManager->removeMount($shareMountPoint->getMountPoint());
233-
}
234-
$this->shareManager->deleteShare($share);
235-
} else {
236-
if ($share->getShareOwner() === $this->sourceUser) {
237-
$share->setShareOwner($this->destinationUser);
238-
}
239-
if ($share->getSharedBy() === $this->sourceUser) {
240-
$share->setSharedBy($this->destinationUser);
241-
}
228+
try {
229+
if ($share->getSharedWith() === $this->destinationUser) {
230+
// Unmount the shares before deleting, so we don't try to get the storage later on.
231+
$shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
232+
if ($shareMountPoint) {
233+
$this->mountManager->removeMount($shareMountPoint->getMountPoint());
234+
}
235+
$this->shareManager->deleteShare($share);
236+
} else {
237+
if ($share->getShareOwner() === $this->sourceUser) {
238+
$share->setShareOwner($this->destinationUser);
239+
}
240+
if ($share->getSharedBy() === $this->sourceUser) {
241+
$share->setSharedBy($this->destinationUser);
242+
}
242243

243-
$this->shareManager->updateShare($share);
244+
$this->shareManager->updateShare($share);
245+
}
246+
} catch (\OCP\Files\NotFoundException $e) {
247+
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
248+
} catch (\Exception $e) {
249+
$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
244250
}
245251
$progress->advance();
246252
}

0 commit comments

Comments
 (0)