Procházet zdrojové kódy

FileSystem.createDirectory now automatically creates intermediate directories (fixed issue #1271)

Simon Krajewski před 12 roky
rodič
revize
6ebebf40b6

+ 7 - 3
std/cpp/_std/sys/FileSystem.hx

@@ -30,7 +30,7 @@ private enum FileKind {
 @:coreApi
 class FileSystem {
 
-	public static function exists( path : String ) : Bool {
+	public static inline function exists( path : String ) : Bool {
 		return sys_exists(path);
 	}
 
@@ -67,8 +67,12 @@ class FileSystem {
 	}
 
 	public static function createDirectory( path : String ) : Void {
-		if (sys_create_dir( path, 493 )==null)
-         throw "Could not create directory:" + path;
+		var parts = [while ((path = haxe.io.Path.directory(path)) != "") path];
+		parts.reverse();
+		for (part in parts) {
+			if (!exists(part) && sys_create_dir( part, 493 )==null)
+				throw "Could not create directory:" + part;
+		}
 	}
 
 	public static function deleteFile( path : String ) : Void {

+ 6 - 1
std/neko/_std/sys/FileSystem.hx

@@ -64,7 +64,12 @@ class FileSystem {
 	}
 
 	public static function createDirectory( path : String ) : Void {
-		sys_create_dir( untyped path.__s, 493 );
+		var parts = [while ((path = haxe.io.Path.directory(path)) != "") path];
+		parts.reverse();
+		for (part in parts) {
+			if (!exists(part))
+				sys_create_dir( untyped part.__s, 493 );
+		}
 	}
 
 	public static function deleteFile( path : String ) : Void {

+ 6 - 1
std/php/_std/sys/FileSystem.hx

@@ -77,7 +77,12 @@ class FileSystem {
 	}
 
 	public static inline function createDirectory( path : String ) : Void {
-		untyped __call__("@mkdir", path, 493); // php default is 0777, neko is 0755
+		var parts = [while ((path = haxe.io.Path.directory(path)) != "") path];
+		parts.reverse();
+		for (part in parts) {
+			if (!exists(part))
+				untyped __call__("@mkdir", part, 493); // php default is 0777, neko is 0755
+		}
 	}
 
 	public static inline function deleteFile( path : String ) : Void {