Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix #32

Now the environment variables can't have more than one ~/.opam/... path
  • Loading branch information...
commit 8a6502336d58fe852b2baa7b9a4288bdf5c98f2c 1 parent 3a0af3c
Thomas Gazagnaire samoht authored

Showing 3 changed files with 14 additions and 7 deletions. Show diff stats Hide diff stats

  1. +3 2 src/client.ml
  2. +5 5 src/run.ml
  3. +6 0 src/utils.ml
5 src/client.ml
@@ -701,10 +701,11 @@ type env = {
701 701 let expand_env t env =
702 702 List.map (fun (ident, symbol, string) ->
703 703 let string = substitute_string t string in
  704 + let clean_env () = try Utils.reset_env_value (Sys.getenv ident) with _ -> [] in
704 705 match symbol with
705 706 | "=" -> (ident, string)
706   - | "+=" -> (ident, try string ^ ":" ^ Sys.getenv ident with _ -> string)
707   - | "=+" -> (ident, try Sys.getenv ident ^ ":" ^ string with _ -> string)
  707 + | "+=" -> (ident, String.concat ":" (string :: clean_env ()))
  708 + | "=+" -> (ident, String.concat ":" (clean_env () @ [string]))
708 709 | _ -> failwith (Printf.sprintf "expand_env: %s is an unknown symbol" symbol)
709 710 ) env
710 711
10 src/run.ml
@@ -180,7 +180,7 @@ let real_path p =
180 180 else
181 181 dir / base
182 182
183   -let add_path bins =
  183 +let replace_path bins =
184 184 let path = ref "<not set>" in
185 185 let env = Unix.environment () in
186 186 for i = 0 to Array.length env - 1 do
@@ -188,9 +188,9 @@ let add_path bins =
188 188 | Some (k,v) -> k,v
189 189 | None -> assert false in
190 190 if k = "PATH" then
191   - let new_path = match List.filter Sys.file_exists bins with
192   - | [] -> v
193   - | l -> String.concat ":" l ^ ":" ^ v in
  191 + let v = Utils.reset_env_value v in
  192 + let bins = List.filter Sys.file_exists bins in
  193 + let new_path = String.concat ":" (bins @ v) in
194 194 env.(i) <- "PATH=" ^ new_path;
195 195 path := new_path;
196 196 done;
@@ -201,7 +201,7 @@ type command = string list
201 201 let run_process ?(add_to_env=[]) ?(add_to_path=[]) = function
202 202 | [] -> invalid_arg "run_process"
203 203 | cmd :: args ->
204   - let env, path = add_path add_to_path in
  204 + let env, path = replace_path add_to_path in
205 205 let add_to_env = List.map (fun (k,v) -> k^"="^v) add_to_env in
206 206 let env = Array.concat [ env; Array.of_list add_to_env ] in
207 207 let name = log_file () in
6 src/utils.ml
@@ -77,4 +77,10 @@ let cut_at = cut_at_aux String.index
77 77
78 78 let rcut_at = cut_at_aux String.rindex
79 79
  80 +let split s c =
  81 + Pcre.split (Pcre.regexp (String.make 1 c)) s
80 82
  83 +(* Remove from a ':' separated list of string the one which are prefix of Globals.root_path *)
  84 +let reset_env_value v =
  85 + let v = split v ':' in
  86 + List.filter (fun v -> not (starts_with ~prefix:!Globals.root_path v)) v

0 comments on commit 8a65023

Please sign in to comment.
Something went wrong with that request. Please try again.