summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-01-24 21:23:59 -0600
committerGitHub <noreply@github.com>2017-01-24 21:23:59 -0600
commit95ab46e3d2d546101b48d1c3f773e3728e25ad43 (patch)
tree230dbc7064b9671304c06463def04c65f7bec8d4 /lib
parentc3e57d228fe07c528771303e0698182553135d06 (diff)
parent269b6527544a4a91687e1e443c6de3f2d42e05dd (diff)
downloadnextcloud-server-95ab46e3d2d546101b48d1c3f773e3728e25ad43.tar.gz
nextcloud-server-95ab46e3d2d546101b48d1c3f773e3728e25ad43.zip
Merge pull request #3030 from nextcloud/filesapi-renamefailcase
Fix files node API failed rename/copy
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Node/File.php56
-rw-r--r--lib/private/Files/Node/Folder.php55
-rw-r--r--lib/private/Files/Node/Node.php80
3 files changed, 82 insertions, 109 deletions
diff --git a/lib/private/Files/Node/File.php b/lib/private/Files/Node/File.php
index c4430b9181d..4bfa5d583f7 100644
--- a/lib/private/Files/Node/File.php
+++ b/lib/private/Files/Node/File.php
@@ -30,6 +30,16 @@ use OCP\Files\NotPermittedException;
class File extends Node implements \OCP\Files\File {
/**
+ * Creates a Folder that represents a non-existing path
+ *
+ * @param string $path path
+ * @return string non-existing node class
+ */
+ protected function createNonExistingNode($path) {
+ return new NonExistingFile($this->root, $this->view, $path);
+ }
+
+ /**
* @return string
* @throws \OCP\Files\NotPermittedException
*/
@@ -114,52 +124,6 @@ class File extends Node implements \OCP\Files\File {
}
/**
- * @param string $targetPath
- * @throws \OCP\Files\NotPermittedException
- * @return \OC\Files\Node\Node
- */
- public function copy($targetPath) {
- $targetPath = $this->normalizePath($targetPath);
- $parent = $this->root->get(dirname($targetPath));
- if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
- $nonExisting = new NonExistingFile($this->root, $this->view, $targetPath);
- $this->root->emit('\OC\Files', 'preCopy', array($this, $nonExisting));
- $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
- $this->view->copy($this->path, $targetPath);
- $targetNode = $this->root->get($targetPath);
- $this->root->emit('\OC\Files', 'postCopy', array($this, $targetNode));
- $this->root->emit('\OC\Files', 'postWrite', array($targetNode));
- return $targetNode;
- } else {
- throw new NotPermittedException();
- }
- }
-
- /**
- * @param string $targetPath
- * @throws \OCP\Files\NotPermittedException
- * @return \OC\Files\Node\Node
- */
- public function move($targetPath) {
- $targetPath = $this->normalizePath($targetPath);
- $parent = $this->root->get(dirname($targetPath));
- if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
- $nonExisting = new NonExistingFile($this->root, $this->view, $targetPath);
- $this->root->emit('\OC\Files', 'preRename', array($this, $nonExisting));
- $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
- $this->view->rename($this->path, $targetPath);
- $targetNode = $this->root->get($targetPath);
- $this->root->emit('\OC\Files', 'postRename', array($this, $targetNode));
- $this->root->emit('\OC\Files', 'postWrite', array($targetNode));
- $this->path = $targetPath;
- $this->fileInfo = null;
- return $targetNode;
- } else {
- throw new NotPermittedException();
- }
- }
-
- /**
* @param string $type
* @param bool $raw
* @return string
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 288a02ef207..fd907f708f3 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -36,6 +36,16 @@ use OCP\Files\NotPermittedException;
class Folder extends Node implements \OCP\Files\Folder {
/**
+ * Creates a Folder that represents a non-existing path
+ *
+ * @param string $path path
+ * @return string non-existing node class
+ */
+ protected function createNonExistingNode($path) {
+ return new NonExistingFolder($this->root, $this->view, $path);
+ }
+
+ /**
* @param string $path path relative to the folder
* @return string
* @throws \OCP\Files\NotPermittedException
@@ -326,51 +336,6 @@ class Folder extends Node implements \OCP\Files\Folder {
}
/**
- * @param string $targetPath
- * @throws \OCP\Files\NotPermittedException
- * @return \OC\Files\Node\Node
- */
- public function copy($targetPath) {
- $targetPath = $this->normalizePath($targetPath);
- $parent = $this->root->get(dirname($targetPath));
- if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
- $nonExisting = new NonExistingFolder($this->root, $this->view, $targetPath);
- $this->root->emit('\OC\Files', 'preCopy', array($this, $nonExisting));
- $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
- $this->view->copy($this->path, $targetPath);
- $targetNode = $this->root->get($targetPath);
- $this->root->emit('\OC\Files', 'postCopy', array($this, $targetNode));
- $this->root->emit('\OC\Files', 'postWrite', array($targetNode));
- return $targetNode;
- } else {
- throw new NotPermittedException('No permission to copy to path');
- }
- }
-
- /**
- * @param string $targetPath
- * @throws \OCP\Files\NotPermittedException
- * @return \OC\Files\Node\Node
- */
- public function move($targetPath) {
- $targetPath = $this->normalizePath($targetPath);
- $parent = $this->root->get(dirname($targetPath));
- if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
- $nonExisting = new NonExistingFolder($this->root, $this->view, $targetPath);
- $this->root->emit('\OC\Files', 'preRename', array($this, $nonExisting));
- $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
- $this->view->rename($this->path, $targetPath);
- $targetNode = $this->root->get($targetPath);
- $this->root->emit('\OC\Files', 'postRename', array($this, $targetNode));
- $this->root->emit('\OC\Files', 'postWrite', array($targetNode));
- $this->path = $targetPath;
- return $targetNode;
- } else {
- throw new NotPermittedException('No permission to move to path');
- }
- }
-
- /**
* Add a suffix to the name in case the file exists
*
* @param string $name
diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php
index 226c182622f..e00debe6903 100644
--- a/lib/private/Files/Node/Node.php
+++ b/lib/private/Files/Node/Node.php
@@ -33,6 +33,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
+// FIXME: this class really should be abstract
class Node implements \OCP\Files\Node {
/**
* @var \OC\Files\View $view
@@ -56,7 +57,7 @@ class Node implements \OCP\Files\Node {
/**
* @param \OC\Files\View $view
- * @param \OC\Files\Node\Root $root
+ * @param \OCP\Files\IRootFolder $root
* @param string $path
* @param FileInfo $fileInfo
*/
@@ -68,6 +69,16 @@ class Node implements \OCP\Files\Node {
}
/**
+ * Creates a Node of the same type that represents a non-existing path
+ *
+ * @param string $path path
+ * @return string non-existing node class
+ */
+ protected function createNonExistingNode($path) {
+ throw new \Exception('Must be implemented by subclasses');
+ }
+
+ /**
* Returns the matching file info
*
* @return FileInfo
@@ -106,28 +117,11 @@ class Node implements \OCP\Files\Node {
return ($this->getPermissions() & $permissions) === $permissions;
}
- /**
- * @param string $targetPath
- * @throws \OCP\Files\NotPermittedException
- * @return \OC\Files\Node\Node
- */
- public function move($targetPath) {
- return;
- }
-
public function delete() {
return;
}
/**
- * @param string $targetPath
- * @return \OC\Files\Node\Node
- */
- public function copy($targetPath) {
- return;
- }
-
- /**
* @param int $mtime
* @throws \OCP\Files\NotPermittedException
*/
@@ -381,4 +375,54 @@ class Node implements \OCP\Files\Node {
public function unlock($type) {
$this->view->unlockFile($this->path, $type);
}
+
+ /**
+ * @param string $targetPath
+ * @throws \OCP\Files\NotPermittedException if copy not allowed or failed
+ * @return \OC\Files\Node\Node
+ */
+ public function copy($targetPath) {
+ $targetPath = $this->normalizePath($targetPath);
+ $parent = $this->root->get(dirname($targetPath));
+ if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
+ $nonExisting = $this->createNonExistingNode($targetPath);
+ $this->root->emit('\OC\Files', 'preCopy', [$this, $nonExisting]);
+ $this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
+ if (!$this->view->copy($this->path, $targetPath)) {
+ throw new NotPermittedException('Could not copy ' . $this->path . ' to ' . $targetPath);
+ }
+ $targetNode = $this->root->get($targetPath);
+ $this->root->emit('\OC\Files', 'postCopy', [$this, $targetNode]);
+ $this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
+ return $targetNode;
+ } else {
+ throw new NotPermittedException('No permission to copy to path ' . $targetPath);
+ }
+ }
+
+ /**
+ * @param string $targetPath
+ * @throws \OCP\Files\NotPermittedException if move not allowed or failed
+ * @return \OC\Files\Node\Node
+ */
+ public function move($targetPath) {
+ $targetPath = $this->normalizePath($targetPath);
+ $parent = $this->root->get(dirname($targetPath));
+ if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
+ $nonExisting = $this->createNonExistingNode($targetPath);
+ $this->root->emit('\OC\Files', 'preRename', [$this, $nonExisting]);
+ $this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
+ if (!$this->view->rename($this->path, $targetPath)) {
+ throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath);
+ }
+ $targetNode = $this->root->get($targetPath);
+ $this->root->emit('\OC\Files', 'postRename', [$this, $targetNode]);
+ $this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
+ $this->path = $targetPath;
+ return $targetNode;
+ } else {
+ throw new NotPermittedException('No permission to move to path ' . $targetPath);
+ }
+ }
+
}