summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-07-01 18:11:05 +0200
committerRobin Appelman <icewind@owncloud.com>2014-05-28 18:16:23 +0200
commitea44f0e20f9685e5d8396380a5fcb383d9efee90 (patch)
tree2fcf4db0224abce0485ce2c42391fbbe505243f4 /lib/private/files
parentc3c9612c99c0bd8b2da9cac262045c43775f2988 (diff)
downloadnextcloud-server-ea44f0e20f9685e5d8396380a5fcb383d9efee90.tar.gz
nextcloud-server-ea44f0e20f9685e5d8396380a5fcb383d9efee90.zip
fix recursive copy and rename for common storage backend
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/storage/common.php47
1 files changed, 38 insertions, 9 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index cfca8ca008c..5fae43d8bf7 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -137,20 +137,49 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
public function rename($path1, $path2) {
- if ($this->copy($path1, $path2)) {
- $this->removeCachedFile($path1);
- return $this->unlink($path1);
+ if ($this->file_exists($path2)) {
+ if ($this->is_dir($path2)) {
+ $this->rmdir($path2);
+ } else if ($this->is_file($path2)) {
+ $this->unlink($path2);
+ }
+ }
+
+ $this->removeCachedFile($path1);
+ if ($this->is_dir($path1)) {
+ return $this->copy($path1, $path2) and $this->rmdir($path1);
} else {
- return false;
+ return $this->copy($path1, $path2) and $this->unlink($path1);
}
}
public function copy($path1, $path2) {
- $source = $this->fopen($path1, 'r');
- $target = $this->fopen($path2, 'w');
- list($count, $result) = \OC_Helper::streamCopy($source, $target);
- $this->removeCachedFile($path2);
- return $result;
+ if ($this->is_dir($path1)) {
+ if ($this->file_exists($path2)) {
+ if ($this->is_dir($path2)) {
+ $this->rmdir($path2);
+ } else if ($this->is_file($path2)) {
+ $this->unlink($path2);
+ }
+ }
+ $dir = $this->opendir($path1);
+ $this->mkdir($path2);
+ while ($file = readdir($dir)) {
+ if (($file != '.') && ($file != '..')) {
+ if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
+ return false;
+ }
+ }
+ }
+ closedir($dir);
+ return true;
+ } else {
+ $source = $this->fopen($path1, 'r');
+ $target = $this->fopen($path2, 'w');
+ list(, $result) = \OC_Helper::streamCopy($source, $target);
+ $this->removeCachedFile($path2);
+ return $result;
+ }
}
public function getMimeType($path) {