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() (from r111898)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112942 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-19 05:06:25 +00:00
parent ef8419f11d
commit 31f0ceac07

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 );
if(is_file($folder) || is_link($folder)) {
unlink($folder);
} else {
$dir = opendir($folder);
while($file = readdir($dir)) {
if(($file == '.' || $file == '..')) continue;
else {
$dir = opendir( $folder );
while( $file = readdir( $dir ) )
if( !preg_match( '/^\.{1,2}$/', $file ) )
self::removeFolder( $folder.'/'.$file );
self::removeFolder($folder . '/' . $file);
}
}
closedir($dir);
if(!$contentsOnly) rmdir($folder);
}
}