]> 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)
committerVincent Petry <pvince81@owncloud.com>
Tue, 3 Dec 2013 09:47:26 +0000 (10:47 +0100)
Backport of 63c898c0

lib/files/storage/local.php
tests/lib/files/storage/storage.php

index f4d7626219b61e515e51ca49ceda242cddf05a39..a6fe01c63d68856e4bba23b21e7577174a551879 100644 (file)
@@ -34,7 +34,27 @@ class Local extends \OC\Files\Storage\Common{
                return @mkdir($this->datadir.$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) {
                return opendir($this->datadir.$path);
index ea3ca7d19e05468e049a1b11ae7bd3a279e586c0..9ee49f8040014ea41b8f9be44a62a9d0515efd75 100644 (file)
@@ -281,7 +281,7 @@ 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'));