From 2d1c6ae726caca3cb9574d7fd6a9e495d218ec83 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 18:02:34 +0200 Subject: overwrite Sabre_DAV_ObjectTree with a faster getNodeForPath --- lib/connector/sabre/objecttree.php | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/connector/sabre/objecttree.php diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php new file mode 100644 index 00000000000..23cbd20cf4e --- /dev/null +++ b/lib/connector/sabre/objecttree.php @@ -0,0 +1,49 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Connector\Sabre; + +use OC\Files\Filesystem; + +class ObjectTree extends \Sabre_DAV_ObjectTree { + /** + * Returns the INode object for the requested path + * + * @param string $path + * @throws \Sabre_DAV_Exception_NotFound + * @return \Sabre_DAV_INode + */ + public function getNodeForPath($path) { + + $path = trim($path, '/'); + if (isset($this->cache[$path])) return $this->cache[$path]; + + // Is it the root node? + if (!strlen($path)) { + return $this->rootNode; + } + + $info = Filesystem::getFileInfo($path); + + if (!$info) { + throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); + } + + if ($info['mimetype'] == 'httpd/unix-directory') { + $node = new \OC_Connector_Sabre_Directory($path); + } else { + $node = new \OC_Connector_Sabre_File($path); + } + + $node->setFileinfoCache($info); + + $this->cache[$path] = $node; + return $node; + + } +} -- cgit v1.2.3 From 4e55d0ef9be67efaacefbba720ef1dbce67d6ede Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 18:11:22 +0200 Subject: make use of the fact that rmdir is already recursive --- lib/connector/sabre/directory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 3d15a2a584d..ed8d085462d 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -222,7 +222,6 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa throw new \Sabre_DAV_Exception_Forbidden(); } if ($this->path != "/Shared") { - foreach($this->getChildren() as $child) $child->delete(); \OC\Files\Filesystem::rmdir($this->path); } -- cgit v1.2.3 From fe0de5fc10f61a7bb3173a04a986b145789b9160 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 18:27:55 +0200 Subject: improved move operation for sabre's objecttree --- lib/connector/sabre/objecttree.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php index 23cbd20cf4e..f51b991d12a 100644 --- a/lib/connector/sabre/objecttree.php +++ b/lib/connector/sabre/objecttree.php @@ -46,4 +46,28 @@ class ObjectTree extends \Sabre_DAV_ObjectTree { return $node; } + + /** + * 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_Forbidden + * @return int + */ + public function move($sourcePath, $destinationPath) { + + $sourceNode = $this->getNodeForPath($sourcePath); + if ($sourceNode instanceof \Sabre_DAV_ICollection and $this->nodeExists($destinationPath)) { + throw new \Sabre_DAV_Exception_Forbidden('Could not copy directory ' . $sourceNode . ', target exists'); + } + list($sourceDir,) = \Sabre_DAV_URLUtil::splitPath($sourcePath); + list($destinationDir,) = \Sabre_DAV_URLUtil::splitPath($destinationPath); + + Filesystem::rename($sourcePath, $destinationPath); + + $this->markDirty($sourceDir); + $this->markDirty($destinationDir); + + } } -- cgit v1.2.3 From 1e0810e80706211e0c7aa736172dc6fd1c34bde7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 18:28:18 +0200 Subject: use new ObjectTree in sabredav --- apps/files/appinfo/remote.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php index 6c92cc80b69..c3e06a0ca76 100644 --- a/apps/files/appinfo/remote.php +++ b/apps/files/appinfo/remote.php @@ -23,7 +23,7 @@ * */ // load needed apps -$RUNTIME_APPTYPES=array('filesystem', 'authentication', 'logging'); +$RUNTIME_APPTYPES = array('filesystem', 'authentication', 'logging'); OC_App::loadApps($RUNTIME_APPTYPES); @@ -35,10 +35,11 @@ $lockBackend = new OC_Connector_Sabre_Locks(); $requestBackend = new OC_Connector_Sabre_Request(); // Create ownCloud Dir -$publicDir = new OC_Connector_Sabre_Directory(''); +$rootDir = new OC_Connector_Sabre_Directory(''); +$objectTree = new \OC\Connector\Sabre\ObjectTree($rootDir); // Fire up server -$server = new Sabre_DAV_Server($publicDir); +$server = new Sabre_DAV_Server($objectTree); $server->httpRequest = $requestBackend; $server->setBaseUri($baseuri); -- cgit v1.2.3 From 93750d2658d52df4475fefde79150a68a8012878 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 19:41:38 +0200 Subject: improved copy operation for objecttree --- lib/connector/sabre/objecttree.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php index f51b991d12a..dbc8c452d1b 100644 --- a/lib/connector/sabre/objecttree.php +++ b/lib/connector/sabre/objecttree.php @@ -70,4 +70,33 @@ class ObjectTree extends \Sabre_DAV_ObjectTree { $this->markDirty($destinationDir); } + + /** + * Copies a file or directory. + * + * This method must work recursively and delete the destination + * if it exists + * + * @param string $source + * @param string $destination + * @return void + */ + public function copy($source, $destination) { + + if (Filesystem::is_file($source)) { + Filesystem::copy($source, $destination); + } else { + Filesystem::mkdir($destination); + $dh = Filesystem::opendir($source); + while ($subnode = readdir($dh)) { + + if ($subnode == '.' || $subnode == '..') continue; + $this->copy($source . '/' . $subnode, $destination . '/' . $subnode); + + } + } + + list($destinationDir,) = \Sabre_DAV_URLUtil::splitPath($destination); + $this->markDirty($destinationDir); + } } -- cgit v1.2.3 From a945ce908b2e8447c4a93b14c711fc066d9e8daf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 19 Jul 2013 02:23:57 +0200 Subject: style fix --- lib/connector/sabre/objecttree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php index dbc8c452d1b..c4ddcbecbb8 100644 --- a/lib/connector/sabre/objecttree.php +++ b/lib/connector/sabre/objecttree.php @@ -34,7 +34,7 @@ class ObjectTree extends \Sabre_DAV_ObjectTree { throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); } - if ($info['mimetype'] == 'httpd/unix-directory') { + if ($info['mimetype'] === 'httpd/unix-directory') { $node = new \OC_Connector_Sabre_Directory($path); } else { $node = new \OC_Connector_Sabre_File($path); -- cgit v1.2.3