BUGFIX Filesystem::removeFolder() did not remove files that ended with a "." when this is a valid file. Remove the regex and replace with specific case for "." and ".."

MINOR Code syntax formatting of Filesystem::removeFolder()


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@111898 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2010-10-11 22:14:59 +00:00 committed by Sam Minnee
parent f3cc5a2b42
commit c427744f73

View File

@ -32,21 +32,20 @@ class Filesystem extends Object {
* @param String $folder Absolute folder path
* @param Boolean $contentsOnly If this is true then the contents of the folder will be removed but not the folder itself
*/
static function removeFolder( $folder, $contentsOnly = false ) {
static function removeFolder($folder, $contentsOnly = false) {
// remove a file encountered by a recursive call.
if( !is_dir( $folder ) || is_link($folder) )
unlink( $folder );
else {
$dir = opendir( $folder );
while( $file = readdir( $dir ) )
if( !preg_match( '/\.{1,2}$/', $file ) )
self::removeFolder( $folder.'/'.$file );
if(is_file($folder) || is_link($folder)) {
unlink($folder);
} else {
$dir = opendir($folder);
while($file = readdir($dir)) {
if(($file == '.' || $file == '..')) continue;
else {
self::removeFolder($folder . '/' . $file);
}
}
closedir($dir);
if(!$contentsOnly) rmdir($folder);
}
}