diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-06-30 09:16:32 -0700 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-06-30 09:16:32 -0700 |
commit | 8beec2015a43839818f9b6f14283b8980ec185b3 (patch) | |
tree | c051d879150ea0fa26f2eb4be037e68460c5c3ea /lib | |
parent | 4d74e8955f4eee870fd83e4eaa30b8e90a0a9f06 (diff) | |
parent | d051d6f9252de915a13e1b053c54f69bcd83f5ee (diff) | |
download | nextcloud-server-8beec2015a43839818f9b6f14283b8980ec185b3.tar.gz nextcloud-server-8beec2015a43839818f9b6f14283b8980ec185b3.zip |
Merge pull request #3763 from owncloud/recursive-rmdir
Make rmdir recursive for local storage
Diffstat (limited to 'lib')
-rw-r--r-- | lib/files/storage/local.php | 22 | ||||
-rw-r--r-- | lib/files/storage/mappedlocal.php | 26 |
2 files changed, 44 insertions, 4 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('.', '..'); |