Andy Li vor 11 Jahren
Ursprung
Commit
98d94eca67

+ 6 - 2
std/cpp/_std/sys/FileSystem.hx

@@ -68,8 +68,12 @@ class FileSystem {
 
 	public static function createDirectory( path : String ) : Void {
 		var path = haxe.io.Path.addTrailingSlash(path);
-		var parts = [while ((path = haxe.io.Path.directory(path)) != "") path];
-		parts.reverse();
+		var _p = null;
+		var parts = [];
+		while (path != (_p = haxe.io.Path.directory(path))) {
+			parts.unshift(path);
+			path = _p;
+		}
 		for (part in parts) {
 			if (part.charCodeAt(part.length - 1) != ":".code && !exists(part) && sys_create_dir( part, 493 )==null)
 				throw "Could not create directory:" + part;

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

@@ -65,8 +65,12 @@ class FileSystem {
 
 	public static function createDirectory( path : String ) : Void {
 		var path = haxe.io.Path.addTrailingSlash(path);
-		var parts = [while ((path = haxe.io.Path.directory(path)) != "") path];
-		parts.reverse();
+		var _p = null;
+		var parts = [];
+		while (path != (_p = haxe.io.Path.directory(path))) {
+			parts.unshift(path);
+			path = _p;
+		}
 		for (part in parts) {
 			if (part.charCodeAt(part.length - 1) != ":".code && !exists(part))
 				sys_create_dir( untyped part.__s, 493 );

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

@@ -78,8 +78,12 @@ class FileSystem {
 
 	public static inline function createDirectory( path : String ) : Void {
 		var path = haxe.io.Path.addTrailingSlash(path);
-		var parts = [while ((path = haxe.io.Path.directory(path)) != "") path];
-		parts.reverse();
+		var _p = null;
+		var parts = [];
+		while (path != (_p = haxe.io.Path.directory(path))) {
+			parts.unshift(path);
+			path = _p;
+		}
 		for (part in parts) {
 			if (part.charCodeAt(part.length - 1) != ":".code && !exists(part))
 				untyped __call__("@mkdir", part, 493); // php default is 0777, neko is 0755

+ 1 - 0
tests/sys/src/Main.hx

@@ -2,6 +2,7 @@ class Main {
 	static public function main() {
 		var runner = new haxe.unit.TestRunner();
 		runner.add(new TestSys());
+		runner.add(new TestFileSystem());
 		runner.add(new io.TestFileInput());
 		var code = runner.run() ? 0 : 1;
 		Sys.exit(code);

+ 21 - 0
tests/sys/src/TestFileSystem.hx

@@ -0,0 +1,21 @@
+import sys.FileSystem;
+
+class TestFileSystem extends haxe.unit.TestCase {
+	function testSimpleDir():Void {
+		assertFalse(FileSystem.exists("testCreateDirectory"));
+		FileSystem.createDirectory("testCreateDirectory");
+		assertTrue(FileSystem.exists("testCreateDirectory"));
+		assertTrue(FileSystem.isDirectory("testCreateDirectory"));
+		FileSystem.deleteDirectory("testCreateDirectory");
+		assertFalse(FileSystem.exists("testCreateDirectory"));
+	}
+
+	function testParentDir():Void {
+		assertFalse(FileSystem.exists("../testCreateDirectory"));
+		FileSystem.createDirectory("../testCreateDirectory");
+		assertTrue(FileSystem.exists("../testCreateDirectory"));
+		assertTrue(FileSystem.isDirectory("../testCreateDirectory"));
+		FileSystem.deleteDirectory("../testCreateDirectory");
+		assertFalse(FileSystem.exists("../testCreateDirectory"));
+	}
+}