From 75879a9e7425144278761b18973b3fb25393867b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 6 Dec 2012 02:31:36 +0100 Subject: [PATCH] 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. --- mdeploy.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mdeploy.php b/mdeploy.php index 9e986b0e0b4..c16bc0fe986 100644 --- a/mdeploy.php +++ b/mdeploy.php @@ -1207,11 +1207,15 @@ class worker extends singleton_pattern { * 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 @@ class worker extends singleton_pattern { } 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; } /**