Browse Source

fix double cwd when doing --cwd, add test (closes #3300)

Dan Korostelev 11 years ago
parent
commit
2fd6200f3e

+ 3 - 3
main.ml

@@ -612,8 +612,8 @@ let rec process_params create pl =
 			loop [] l
 			loop [] l
 		| "--cwd" :: dir :: l ->
 		| "--cwd" :: dir :: l ->
 			(* we need to change it immediately since it will affect hxml loading *)
 			(* we need to change it immediately since it will affect hxml loading *)
-			(try Unix.chdir dir with _ -> ());
-			loop (dir :: "--cwd" :: acc) l
+			(try Unix.chdir dir with _ -> raise (Arg.Bad "Invalid directory"));
+			loop acc l
 		| "--connect" :: hp :: l ->
 		| "--connect" :: hp :: l ->
 			(match !global_cache with
 			(match !global_cache with
 			| None ->
 			| None ->
@@ -1213,7 +1213,7 @@ try
 			assert false
 			assert false
 		),"<[host:]port> : connect on the given port and run commands there)");
 		),"<[host:]port> : connect on the given port and run commands there)");
 		("--cwd", Arg.String (fun dir ->
 		("--cwd", Arg.String (fun dir ->
-			(try Unix.chdir dir with _ -> raise (Arg.Bad "Invalid directory"))
+			assert false
 		),"<dir> : set current working directory");
 		),"<dir> : set current working directory");
 		("-version",Arg.Unit (fun() ->
 		("-version",Arg.Unit (fun() ->
 			message ctx s_version Ast.null_pos;
 			message ctx s_version Ast.null_pos;

+ 0 - 0
tests/misc/projects/Issue3300/dir/keepme


+ 1 - 0
tests/misc/projects/Issue3300/test-cwd-fail.hxml

@@ -0,0 +1 @@
+--cwd unexistant

+ 1 - 0
tests/misc/projects/Issue3300/test-cwd.hxml

@@ -0,0 +1 @@
+--cwd dir