]> source.dussan.org Git - nextcloud-server.git/commitdiff
Skip broken shares when transferring ownership (#26527) 2115/head
authorVincent Petry <pvince81@owncloud.com>
Mon, 7 Nov 2016 19:20:16 +0000 (20:20 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 14 Nov 2016 14:18:34 +0000 (15:18 +0100)
apps/files/lib/Command/TransferOwnership.php

index 3b51e4a9e6d5c4352f79c859a080f20902994e04..7ae968932d9bda9258f8080f244f4dc4b21f5f22 100644 (file)
@@ -224,22 +224,28 @@ class TransferOwnership extends Command {
                $progress = new ProgressBar($output, count($this->shares));
 
                foreach($this->shares as $share) {
-                       if ($share->getSharedWith() === $this->destinationUser) {
-                               // Unmount the shares before deleting, so we don't try to get the storage later on.
-                               $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
-                               if ($shareMountPoint) {
-                                       $this->mountManager->removeMount($shareMountPoint->getMountPoint());
-                               }
-                               $this->shareManager->deleteShare($share);
-                       } else {
-                               if ($share->getShareOwner() === $this->sourceUser) {
-                                       $share->setShareOwner($this->destinationUser);
-                               }
-                               if ($share->getSharedBy() === $this->sourceUser) {
-                                       $share->setSharedBy($this->destinationUser);
-                               }
+                       try {
+                               if ($share->getSharedWith() === $this->destinationUser) {
+                                       // Unmount the shares before deleting, so we don't try to get the storage later on.
+                                       $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
+                                       if ($shareMountPoint) {
+                                               $this->mountManager->removeMount($shareMountPoint->getMountPoint());
+                                       }
+                                       $this->shareManager->deleteShare($share);
+                               } else {
+                                       if ($share->getShareOwner() === $this->sourceUser) {
+                                               $share->setShareOwner($this->destinationUser);
+                                       }
+                                       if ($share->getSharedBy() === $this->sourceUser) {
+                                               $share->setSharedBy($this->destinationUser);
+                                       }
 
-                               $this->shareManager->updateShare($share);
+                                       $this->shareManager->updateShare($share);
+                               }
+                       } catch (\OCP\Files\NotFoundException $e) {
+                               $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
+                       } catch (\Exception $e) {
+                               $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
                        }
                        $progress->advance();
                }