/**
  * @param OutputInterface $output
  */
 private function restoreShares(OutputInterface $output)
 {
     $output->writeln("Restoring shares ...");
     $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);
             }
             $this->shareManager->updateShare($share);
         }
         $progress->advance();
     }
     $progress->finish();
     $output->writeln('');
 }
Example #2
0
 /**
  * Moves a file from one location to another
  *
  * @param string $sourcePath The path to the file which should be moved
  * @param string $destinationPath The full destination path, so not just the destination parent node
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @throws \Sabre\DAV\Exception\Forbidden
  * @return int
  */
 public function move($sourcePath, $destinationPath)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $targetNodeExists = $this->nodeExists($destinationPath);
     $sourceNode = $this->getNodeForPath($sourcePath);
     if ($sourceNode instanceof \Sabre\DAV\ICollection && $targetNodeExists) {
         throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode->getName() . ', target exists');
     }
     list($sourceDir, ) = \Sabre\HTTP\URLUtil::splitPath($sourcePath);
     list($destinationDir, ) = \Sabre\HTTP\URLUtil::splitPath($destinationPath);
     $isMovableMount = false;
     $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath));
     $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath));
     if ($sourceMount instanceof MoveableMount && $internalPath === '') {
         $isMovableMount = true;
     }
     try {
         $sameFolder = $sourceDir === $destinationDir;
         // if we're overwriting or same folder
         if ($targetNodeExists || $sameFolder) {
             // note that renaming a share mount point is always allowed
             if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         } else {
             if (!$this->fileView->isCreatable($destinationDir)) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         if (!$sameFolder) {
             // moving to a different folder, source will be gone, like a deletion
             // note that moving a share mount point is always allowed
             if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         $fileName = basename($destinationPath);
         try {
             $this->fileView->verifyPath($destinationDir, $fileName);
         } catch (\OCP\Files\InvalidPathException $ex) {
             throw new InvalidPath($ex->getMessage());
         }
         $renameOkay = $this->fileView->rename($sourcePath, $destinationPath);
         if (!$renameOkay) {
             throw new \Sabre\DAV\Exception\Forbidden('');
         }
     } catch (StorageNotAvailableException $e) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
     } catch (ForbiddenException $ex) {
         throw new Forbidden($ex->getMessage(), $ex->getRetry());
     } catch (LockedException $e) {
         throw new FileLocked($e->getMessage(), $e->getCode(), $e);
     }
     $this->markDirty($sourceDir);
     $this->markDirty($destinationDir);
 }
 public function testPathCreateChecksContainsNoSharedMount()
 {
     $path = $this->getMock('\\OCP\\Files\\Folder');
     $path->method('getPath')->willReturn('path');
     $mount = $this->getMock('\\OCP\\Files\\Mount\\IMountPoint');
     $storage = $this->getMock('\\OCP\\Files\\Storage');
     $mount->method('getStorage')->willReturn($storage);
     $storage->method('instanceOfStorage')->with('\\OCA\\Files_Sharing\\ISharedStorage')->willReturn(false);
     $this->mountManager->method('findIn')->with('path')->willReturn([$mount]);
     $this->invokePrivate($this->manager, 'pathCreateChecks', [$path]);
 }
Example #4
0
 /**
  * @param File|Folder $path
  */
 protected function pathCreateChecks($path)
 {
     // Make sure that we do not share a path that contains a shared mountpoint
     if ($path instanceof \OCP\Files\Folder) {
         $mounts = $this->mountManager->findIn($path->getPath());
         foreach ($mounts as $mount) {
             if ($mount->getStorage()->instanceOfStorage('\\OCA\\Files_Sharing\\ISharedStorage')) {
                 throw new \InvalidArgumentException('Path contains files shared with you');
             }
         }
     }
 }