]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make rmdir recursive for local storage
authorRobin Appelman <icewind@owncloud.com>
Thu, 6 Jun 2013 18:47:20 +0000 (20:47 +0200)
committerRobin Appelman <icewind@owncloud.com>
Mon, 17 Jun 2013 15:34:09 +0000 (17:34 +0200)
lib/files/storage/local.php
tests/lib/files/storage/storage.php

index d684905bf9a4e5856762f1ffe44076234dc55311..b08fd73ce1977cd41d1b1e9d51f7f47715bd7080 100644 (file)
@@ -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) {
index 0e22f26ae838f79c7fe76f8500d1dbf5670006a0..fb3e05e66b3c74380aa9196545cd917d48231708 100644 (file)
@@ -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'));
+       }
 }