Skip to content
Snippets Groups Projects
Commit 63c898c0 authored by Robin Appelman's avatar Robin Appelman
Browse files

Make rmdir recursive for local storage

parent 6156d718
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,27 @@ if (\OC_Util::runningOnWindows()) {
}
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) {
......
......@@ -263,4 +263,16 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->instance->touch('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'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment