mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
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.
This commit is contained in:
parent
b68bbc5ae1
commit
75879a9e74
1 changed files with 16 additions and 5 deletions
21
mdeploy.php
21
mdeploy.php
|
@ -1207,11 +1207,15 @@ class worker extends singleton_pattern {
|
||||||
* Deletes the given directory recursively
|
* Deletes the given directory recursively
|
||||||
*
|
*
|
||||||
* @param string $path full path to the directory
|
* @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)) {
|
if (!file_exists($path)) {
|
||||||
return;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
|
@ -1228,15 +1232,22 @@ class worker extends singleton_pattern {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($filepath)) {
|
if (is_dir($filepath)) {
|
||||||
$this->remove_directory($filepath);
|
$result = $result && $this->remove_directory($filepath, false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
unlink($filepath);
|
$result = $result && unlink($filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
return rmdir($path);
|
|
||||||
|
if (!$keeppathroot) {
|
||||||
|
$result = $result && rmdir($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearstatcache();
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue