summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-06-30 09:16:32 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-06-30 09:16:32 -0700
commit8beec2015a43839818f9b6f14283b8980ec185b3 (patch)
treec051d879150ea0fa26f2eb4be037e68460c5c3ea
parent4d74e8955f4eee870fd83e4eaa30b8e90a0a9f06 (diff)
parentd051d6f9252de915a13e1b053c54f69bcd83f5ee (diff)
downloadnextcloud-server-8beec2015a43839818f9b6f14283b8980ec185b3.tar.gz
nextcloud-server-8beec2015a43839818f9b6f14283b8980ec185b3.zip
Merge pull request #3763 from owncloud/recursive-rmdir
Make rmdir recursive for local storage
-rw-r--r--lib/files/storage/local.php22
-rw-r--r--lib/files/storage/mappedlocal.php26
-rw-r--r--tests/lib/files/storage/storage.php14
3 files changed, 57 insertions, 5 deletions
diff --git a/lib/files/storage/local.php b/lib/files/storage/local.php
index d684905bf9a..b08fd73ce19 100644
--- a/lib/files/storage/local.php
+++ b/lib/files/storage/local.php
@@ -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) {
diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php
index ba3fcdc5c9e..cf5d9b3ef4f 100644
--- a/lib/files/storage/mappedlocal.php
+++ b/lib/files/storage/mappedlocal.php
@@ -34,10 +34,30 @@ class MappedLocal extends \OC\Files\Storage\Common{
return @mkdir($this->buildPath($path));
}
public function rmdir($path) {
- if ($result = @rmdir($this->buildPath($path))) {
- $this->cleanMapper($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))) {
+ $this->cleanMapper($path);
+ }
+ return $result;
+ } catch (\UnexpectedValueException $e) {
+ return false;
}
- return $result;
}
public function opendir($path) {
$files = array('.', '..');
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index 0e22f26ae83..fb3e05e66b3 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -258,9 +258,21 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertEquals(file_get_contents($textFile), $content);
}
- public function testTouchCreateFile(){
+ public function testTouchCreateFile() {
$this->assertFalse($this->instance->file_exists('foo'));
$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'));
+ }
}