]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix recursive rename for local storage backend
authorRobin Appelman <icewind@owncloud.com>
Mon, 1 Jul 2013 15:45:01 +0000 (17:45 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 28 May 2014 16:16:23 +0000 (18:16 +0200)
lib/private/files/storage/local.php
tests/lib/files/storage/storage.php

index aaa9f3c858e4d6ee2e3b8838470693dab966b7b5..ec28ebac6ee97b304c01bacea0093892363f051d 100644 (file)
@@ -177,9 +177,11 @@ if (\OC_Util::runningOnWindows()) {
                                return false;
                        }
 
-                       if ($return = rename($this->datadir . $path1, $this->datadir . $path2)) {
+                       if ($this->is_dir($path2)) {
+                               $this->rmdir($path2);
                        }
-                       return $return;
+
+                       return rename($this->datadir . $path1, $this->datadir . $path2);
                }
 
                public function copy($path1, $path2) {
index 92afd47673a14f71a1d4495ae1525719b089613b..4a4626fc5c5436169225af670b974c8482ebc112 100644 (file)
@@ -385,4 +385,20 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
                $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt'));
                $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt'));
        }
+
+       public function testRenameOverWriteDirectory() {
+               $this->instance->mkdir('source');
+               $this->instance->file_put_contents('source/test1.txt', 'foo');
+
+               $this->instance->mkdir('target');
+               $this->instance->file_put_contents('target/test1.txt', 'bar');
+               $this->instance->file_put_contents('target/test2.txt', 'bar');
+
+               $this->instance->rename('source', 'target');
+
+               $this->assertFalse($this->instance->file_exists('source'));
+               $this->assertFalse($this->instance->file_exists('source/test1.txt'));
+               $this->assertFalse($this->instance->file_exists('target/test2.txt'));
+               $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
+       }
 }