From 6e7dfac65a2e134f079d681d330d78721850f2fb Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 24 Feb 2012 15:41:06 +0000 Subject: [PATCH] move wfRecursiveRemoveDir to global functions That useful method was hidden in SeleniumWebSettings. I need it to clean up test files leakages. --- includes/GlobalFunctions.php | 23 +++++++++++++++++++++++ includes/SeleniumWebSettings.php | 18 ------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 77820eaad7..3151755628 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2615,6 +2615,29 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) { return $ok; } +/** + * Remove a directory and all its content. + * Does not hide error. + */ +function wfRecursiveRemoveDir( $dir ) { + wfDebug( __FUNCTION__ . "( $dir )\n" ); + // taken from http://de3.php.net/manual/en/function.rmdir.php#98622 + if ( is_dir( $dir ) ) { + $objects = scandir( $dir ); + foreach ( $objects as $object ) { + if ( $object != "." && $object != ".." ) { + if ( filetype( $dir . '/' . $object ) == "dir" ) { + wfRecursiveRemoveDir( $dir . '/' . $object ); + } else { + unlink( $dir . '/' . $object ); + } + } + } + reset( $objects ); + rmdir( $dir ); + } +} + /** * @param $nr Mixed: the number to format * @param $acc Integer: the number of digits after the decimal point, default 2 diff --git a/includes/SeleniumWebSettings.php b/includes/SeleniumWebSettings.php index 56afa92941..34d829ca0e 100644 --- a/includes/SeleniumWebSettings.php +++ b/includes/SeleniumWebSettings.php @@ -201,21 +201,3 @@ function switchToTestResources( $testResourceName, $switchDB = true ) { $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); $wgUploadPath = $testUploadPath; } - -function wfRecursiveRemoveDir( $dir ) { - // taken from http://de3.php.net/manual/en/function.rmdir.php#98622 - if ( is_dir( $dir ) ) { - $objects = scandir( $dir ); - foreach ( $objects as $object ) { - if ( $object != "." && $object != ".." ) { - if ( filetype( $dir . '/' . $object ) == "dir" ) { - wfRecursiveRemoveDir( $dir . '/' . $object ); - } else { - unlink( $dir . '/' . $object ); - } - } - } - reset( $objects ); - rmdir( $dir ); - } -} \ No newline at end of file -- 2.20.1