Permalink
Browse files

MDL-36963 Improve mdeploy worker::remove_directory() method

The additional parameter allows to use this method without actual
removing the root of the path. That is, it is now possible to remove
the content of a folder only.
  • Loading branch information...
mudrd8mz committed Dec 6, 2012
1 parent 606e2c8 commit e399d3269422aafcf4eecd0b157ad572ff7361ac
Showing with 16 additions and 5 deletions.
  1. +16 −5 mdeploy.php
View
@@ -1207,11 +1207,15 @@ protected function move_directory_into($source, $target, $keepsourceroot = false
* Deletes the given directory recursively
*
* @param string $path full path to the directory
+ * @param bool $keeppathroot should the root of the $path be kept (i.e. remove the content only) or removed too
+ * @return bool
*/
- protected function remove_directory($path) {
+ protected function remove_directory($path, $keeppathroot = false) {
+
+ $result = true;
if (!file_exists($path)) {
- return;
+ return $result;
}
if (is_dir($path)) {
@@ -1228,15 +1232,22 @@ protected function remove_directory($path) {
}
if (is_dir($filepath)) {
- $this->remove_directory($filepath);
+ $result = $result && $this->remove_directory($filepath, false);
} else {
- unlink($filepath);
+ $result = $result && unlink($filepath);
}
}
closedir($handle);
- return rmdir($path);
+
+ if (!$keeppathroot) {
+ $result = $result && rmdir($path);
+ }
+
+ clearstatcache();
+
+ return $result;
}
/**

0 comments on commit e399d32

Please sign in to comment.