add recursive copy to local storage backend
This commit is contained in:
parent
38c1da0976
commit
03ba497a8c
2 changed files with 84 additions and 7 deletions
|
@ -179,20 +179,34 @@ if (\OC_Util::runningOnWindows()) {
|
|||
|
||||
if ($this->is_dir($path2)) {
|
||||
$this->rmdir($path2);
|
||||
} else if ($this->is_file($path2)) {
|
||||
$this->unlink($path2);
|
||||
}
|
||||
|
||||
return rename($this->datadir . $path1, $this->datadir . $path2);
|
||||
}
|
||||
|
||||
public function copy($path1, $path2) {
|
||||
if ($this->is_dir($path2)) {
|
||||
if (!$this->file_exists($path2)) {
|
||||
$this->mkdir($path2);
|
||||
if ($this->is_dir($path1)) {
|
||||
if ($this->is_dir($path2)) {
|
||||
$this->rmdir($path2);
|
||||
} else if ($this->is_file($path2)) {
|
||||
$this->unlink($path2);
|
||||
}
|
||||
$source = substr($path1, strrpos($path1, '/') + 1);
|
||||
$path2 .= $source;
|
||||
$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 {
|
||||
return copy($this->datadir . $path1, $this->datadir . $path2);
|
||||
}
|
||||
return copy($this->datadir . $path1, $this->datadir . $path2);
|
||||
}
|
||||
|
||||
public function fopen($path, $mode) {
|
||||
|
|
|
@ -373,7 +373,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertFalse($this->instance->file_exists('source/test1.txt'));
|
||||
$this->assertFalse($this->instance->file_exists('source/test2.txt'));
|
||||
$this->assertFalse($this->instance->file_exists('source/subfolder'));
|
||||
$this->assertFalse($this->instance->file_exists('source/test.txt'));
|
||||
$this->assertFalse($this->instance->file_exists('source/subfolder/test.txt'));
|
||||
|
||||
$this->assertTrue($this->instance->file_exists('target'));
|
||||
$this->assertTrue($this->instance->file_exists('target/test1.txt'));
|
||||
|
@ -401,4 +401,67 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertFalse($this->instance->file_exists('target/test2.txt'));
|
||||
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
||||
}
|
||||
|
||||
public function testRenameOverWriteDirectoryOverFile() {
|
||||
$this->instance->mkdir('source');
|
||||
$this->instance->file_put_contents('source/test1.txt', 'foo');
|
||||
|
||||
$this->instance->file_put_contents('target', 'bar');
|
||||
|
||||
$this->instance->rename('source', 'target');
|
||||
|
||||
$this->assertFalse($this->instance->file_exists('source'));
|
||||
$this->assertFalse($this->instance->file_exists('source/test1.txt'));
|
||||
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
||||
}
|
||||
|
||||
public function testCopyDirectory() {
|
||||
$this->instance->mkdir('source');
|
||||
$this->instance->file_put_contents('source/test1.txt', 'foo');
|
||||
$this->instance->file_put_contents('source/test2.txt', 'qwerty');
|
||||
$this->instance->mkdir('source/subfolder');
|
||||
$this->instance->file_put_contents('source/subfolder/test.txt', 'bar');
|
||||
$this->instance->copy('source', 'target');
|
||||
|
||||
$this->assertTrue($this->instance->file_exists('source'));
|
||||
$this->assertTrue($this->instance->file_exists('source/test1.txt'));
|
||||
$this->assertTrue($this->instance->file_exists('source/test2.txt'));
|
||||
$this->assertTrue($this->instance->file_exists('source/subfolder'));
|
||||
$this->assertTrue($this->instance->file_exists('source/subfolder/test.txt'));
|
||||
|
||||
$this->assertTrue($this->instance->file_exists('target'));
|
||||
$this->assertTrue($this->instance->file_exists('target/test1.txt'));
|
||||
$this->assertTrue($this->instance->file_exists('target/test2.txt'));
|
||||
$this->assertTrue($this->instance->file_exists('target/subfolder'));
|
||||
$this->assertTrue($this->instance->file_exists('target/subfolder/test.txt'));
|
||||
|
||||
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
||||
$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 testCopyOverWriteDirectory() {
|
||||
$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->copy('source', 'target');
|
||||
|
||||
$this->assertFalse($this->instance->file_exists('target/test2.txt'));
|
||||
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
||||
}
|
||||
|
||||
public function testCopyOverWriteDirectoryOverFile() {
|
||||
$this->instance->mkdir('source');
|
||||
$this->instance->file_put_contents('source/test1.txt', 'foo');
|
||||
|
||||
$this->instance->file_put_contents('target', 'bar');
|
||||
|
||||
$this->instance->copy('source', 'target');
|
||||
|
||||
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue