From 93750d2658d52df4475fefde79150a68a8012878 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 19:41:38 +0200 Subject: [PATCH] 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 f51b991d12..dbc8c452d1 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); + } }