Browse Source

fixed "Unix.Unix_error" failure if output directory contains a trailing slash (#6212, #6768)

Alexander Kuzmenko 7 years ago
parent
commit
5b9de19d48
4 changed files with 11 additions and 5 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 8 1
      src/context/common.ml
  3. 1 1
      src/generators/gencs.ml
  4. 1 3
      src/generators/genjava.ml

+ 1 - 0
extra/CHANGES.txt

@@ -3,6 +3,7 @@
 	Bugfixes:
 
 	all : fixed a bug when Haxe compiler couldn't find std lib on Linux if executed by another  program
+	all : fixed "Unix.Unix_error" compiler failure if output directory contains a trailing slash (#6212, #6768)
 	php7 : fixed an issue with "Object" used as a class name for PHP 7.2 (it's a new keyword in php) (#6838)
 	as3 : fixed "inifinite recursion" compiler error for classes named "Object"
 

+ 8 - 1
src/context/common.ml

@@ -1034,7 +1034,14 @@ let rec mkdir_recursive base dir_list =
 				   | "/" -> "/" ^ dir
 				   | _ -> base ^ "/" ^ dir
 		in
-		if not ( (path = "") || ( ((String.length path) = 2) && ((String.sub path 1 1) = ":") ) ) then
+		let path_len = String.length path in
+		let path =
+			if path_len > 0 && path.[path_len - 1] = '/' || path.[path_len - 1] == '\\' then
+				String.sub path 0 (path_len - 1)
+			else
+				path
+		in
+		if not ( (path = "") || ( (path_len = 2) && ((String.sub path 1 1) = ":") ) ) then
 			if not (Sys.file_exists path) then
 				Unix.mkdir path 0o755;
 		mkdir_recursive (if (path = "") then "/" else path) remaining

+ 1 - 1
src/generators/gencs.ml

@@ -3278,7 +3278,7 @@ let configure gen =
 	TypeParams.RenameTypeParameters.run gen;
 
 	let parts = Str.split_delim (Str.regexp "[\\/]+") gen.gcon.file in
-	mkdir_recursive "" parts;
+	mkdir_from_path gen.gcon.file;
 
 	List.iter (fun md_def ->
 		let source_dir = gen.gcon.file ^ "/src/" ^ (String.concat "/" (fst (path_of_md_def md_def))) in

+ 1 - 3
src/generators/genjava.ml

@@ -2417,9 +2417,7 @@ let configure gen =
 	let str_cl = match gen.gcon.basic.tstring with | TInst(cl,_) -> cl | _ -> assert false in
 	str_cl.cl_super <- Some (get_cl (get_type gen (["haxe";"lang"], "NativeString")), []);
 
-	let mkdir dir = if not (Sys.file_exists dir) then Unix.mkdir dir 0o755 in
-	mkdir gen.gcon.file;
-	mkdir (gen.gcon.file ^ "/src");
+	mkdir_from_path (gen.gcon.file ^ "/src");
 
 	let out_files = ref [] in