Remove ObjectTree::move and let is use the IMoveTarget approach instead
This removes the duplicated code
This commit is contained in:
parent
0a9f7730d0
commit
82b967d3f9
|
@ -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.
|
* Copies a file or directory.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue