]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove ObjectTree::move and let is use the IMoveTarget approach instead
authorVincent Petry <pvince81@owncloud.com>
Wed, 29 Mar 2017 09:16:41 +0000 (11:16 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 26 Apr 2017 13:35:08 +0000 (15:35 +0200)
This removes the duplicated code

apps/dav/lib/Connector/Sabre/ObjectTree.php

index 554a7ad86ca8a28ed135f70b395879e116962f0f..acc6dcc3be3cffaefc123379081cf946633b37d3 100644 (file)
@@ -184,104 +184,6 @@ class ObjectTree extends \Sabre\DAV\Tree {
 
        }
 
-       /**
-        * 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 FileLocked
-        * @throws Forbidden
-        * @throws InvalidPath
-        * @throws \Sabre\DAV\Exception\Forbidden
-        * @throws \Sabre\DAV\Exception\Locked
-        * @throws \Sabre\DAV\Exception\NotFound
-        * @throws \Sabre\DAV\Exception\ServiceUnavailable
-        * @return int
-        */
-       public function move($sourcePath, $destinationPath) {
-               if (!$this->fileView) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
-               }
-
-               $infoDestination = $this->fileView->getFileInfo(dirname($destinationPath));
-               if (dirname($destinationPath) === dirname($sourcePath)) {
-                       $sourcePermission = $infoDestination && $infoDestination->isUpdateable();
-                       $destinationPermission = $sourcePermission;
-               } else {
-                       $infoSource = $this->fileView->getFileInfo($sourcePath);
-                       if ($this->fileView->file_exists($destinationPath)) {
-                               $destinationPermission = $infoDestination && $infoDestination->isUpdateable();
-                       } else {
-                               $destinationPermission = $infoDestination && $infoDestination->isCreatable();
-                       }
-                       $sourcePermission =  $infoSource && $infoSource->isDeletable();
-               }
-
-               if (!$destinationPermission || !$sourcePermission) {
-                       throw new Forbidden('No permissions to move object.');
-               }
-
-               $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);
-
-       }
-
        /**
         * Copies a file or directory.
         *