소스 검색

Fix #6489 (#8548)

* fix #6489

* test

* consistent

* fix eval
Aurel 6 년 전
부모
커밋
ff76576bf3
5개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      src/macro/eval/evalStdLib.ml
  2. 2 0
      std/cpp/_std/sys/FileSystem.hx
  3. 2 0
      std/hl/_std/sys/FileSystem.hx
  4. 2 0
      std/neko/_std/sys/FileSystem.hx
  5. 5 0
      tests/sys/src/TestFileSystem.hx

+ 1 - 0
src/macro/eval/evalStdLib.ml

@@ -1189,6 +1189,7 @@ module StdFileSystem = struct
 
 	let patch_path s =
 		if String.length s > 1 && String.length s <= 3 && s.[1] = ':' then Path.add_trailing_slash s
+		else if s = "/" then "/"
 		else remove_trailing_slash s
 
 	let createDirectory = vfun1 (fun path ->

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

@@ -104,6 +104,8 @@ class FileSystem {
 	private static inline function makeCompatiblePath(path:String):String {
 		return if (path.charCodeAt(1) == ":".code && path.length <= 3) {
 			haxe.io.Path.addTrailingSlash(path);
+		} else if (path == "/") {
+			"/";
 		} else {
 			haxe.io.Path.removeTrailingSlashes(path);
 		}

+ 2 - 0
std/hl/_std/sys/FileSystem.hx

@@ -102,6 +102,8 @@ class FileSystem {
 	private static inline function makeCompatiblePath(path:String):String {
 		return if (path.charCodeAt(1) == ":".code && path.length <= 3) {
 			haxe.io.Path.addTrailingSlash(path);
+		} else if (path == "/") {
+			"/";
 		} else {
 			haxe.io.Path.removeTrailingSlashes(path);
 		}

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

@@ -104,6 +104,8 @@ class FileSystem {
 	private static inline function makeCompatiblePath(path:String):String {
 		return if (path.charCodeAt(1) == ":".code && path.length <= 3) {
 			haxe.io.Path.addTrailingSlash(path);
+		} else if (path == "/") {
+			"/";
 		} else {
 			haxe.io.Path.removeTrailingSlashes(path);
 		}

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

@@ -94,6 +94,11 @@ class TestFileSystem extends utest.Test {
 		}
 	}
 
+	function testRootExists() {
+		Assert.isTrue(FileSystem.exists("/"));
+		Assert.isTrue(FileSystem.stat("/") != null);
+	}
+
 	function testWindowsSpecialCases() {
 		if (Sys.systemName() != "Windows" #if python || true #end) {
 			Assert.isTrue(true);