mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
f3cc5a2b42
commit
c427744f73
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user