Merge pull request #3763 from owncloud/recursive-rmdir
Make rmdir recursive for local storage
This commit is contained in:
commit
8beec2015a
|
@ -39,7 +39,27 @@ if (\OC_Util::runningOnWindows()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rmdir($path) {
|
public function rmdir($path) {
|
||||||
return @rmdir($this->datadir . $path);
|
try {
|
||||||
|
$it = new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($this->datadir . $path),
|
||||||
|
\RecursiveIteratorIterator::CHILD_FIRST
|
||||||
|
);
|
||||||
|
foreach ($it as $file) {
|
||||||
|
/**
|
||||||
|
* @var \SplFileInfo $file
|
||||||
|
*/
|
||||||
|
if (in_array($file->getBasename(), array('.', '..'))) {
|
||||||
|
continue;
|
||||||
|
} elseif ($file->isDir()) {
|
||||||
|
rmdir($file->getPathname());
|
||||||
|
} elseif ($file->isFile() || $file->isLink()) {
|
||||||
|
unlink($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rmdir($this->datadir . $path);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function opendir($path) {
|
public function opendir($path) {
|
||||||
|
|
|
@ -34,10 +34,30 @@ class MappedLocal extends \OC\Files\Storage\Common{
|
||||||
return @mkdir($this->buildPath($path));
|
return @mkdir($this->buildPath($path));
|
||||||
}
|
}
|
||||||
public function rmdir($path) {
|
public function rmdir($path) {
|
||||||
|
try {
|
||||||
|
$it = new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($this->buildPath($path)),
|
||||||
|
\RecursiveIteratorIterator::CHILD_FIRST
|
||||||
|
);
|
||||||
|
foreach ($it as $file) {
|
||||||
|
/**
|
||||||
|
* @var \SplFileInfo $file
|
||||||
|
*/
|
||||||
|
if (in_array($file->getBasename(), array('.', '..'))) {
|
||||||
|
continue;
|
||||||
|
} elseif ($file->isDir()) {
|
||||||
|
rmdir($file->getPathname());
|
||||||
|
} elseif ($file->isFile() || $file->isLink()) {
|
||||||
|
unlink($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($result = @rmdir($this->buildPath($path))) {
|
if ($result = @rmdir($this->buildPath($path))) {
|
||||||
$this->cleanMapper($path);
|
$this->cleanMapper($path);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public function opendir($path) {
|
public function opendir($path) {
|
||||||
$files = array('.', '..');
|
$files = array('.', '..');
|
||||||
|
|
|
@ -258,9 +258,21 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals(file_get_contents($textFile), $content);
|
$this->assertEquals(file_get_contents($textFile), $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTouchCreateFile(){
|
public function testTouchCreateFile() {
|
||||||
$this->assertFalse($this->instance->file_exists('foo'));
|
$this->assertFalse($this->instance->file_exists('foo'));
|
||||||
$this->instance->touch('foo');
|
$this->instance->touch('foo');
|
||||||
$this->assertTrue($this->instance->file_exists('foo'));
|
$this->assertTrue($this->instance->file_exists('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRecursiveRmdir() {
|
||||||
|
$this->instance->mkdir('folder');
|
||||||
|
$this->instance->mkdir('folder/bar');
|
||||||
|
$this->instance->file_put_contents('folder/asd.txt', 'foobar');
|
||||||
|
$this->instance->file_put_contents('folder/bar/foo.txt', 'asd');
|
||||||
|
$this->instance->rmdir('folder');
|
||||||
|
$this->assertFalse($this->instance->file_exists('folder/asd.txt'));
|
||||||
|
$this->assertFalse($this->instance->file_exists('folder/bar/foo.txt'));
|
||||||
|
$this->assertFalse($this->instance->file_exists('folder/bar'));
|
||||||
|
$this->assertFalse($this->instance->file_exists('folder'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue