From f7671c122f08d3a55932f4f407ba715d4b656299 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Fri, 15 Jun 2018 15:26:11 +0200 Subject: [PATCH] Ensure OPAM_SWITCH_PREFIX is correctly set by `opam env` even if the files have been moved / the switch renamed. This is not a complete fix to #3411 (doesn't add a warning, and the PATH will only become correct once a package operation has been done), but avoids the pathological cases. --- src/state/opamEnv.ml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/state/opamEnv.ml b/src/state/opamEnv.ml index ea156a25aa4..bf722975f36 100644 --- a/src/state/opamEnv.ml +++ b/src/state/opamEnv.ml @@ -247,6 +247,13 @@ let get_opam_raw ?(set_opamroot=false) ?(set_opamswitch=false) ~force_path root switch = let env_file = OpamPath.Switch.environment root switch in let upd = OpamFile.Environment.safe_read env_file in + let upd = + ("OPAM_SWITCH_PREFIX", Eq, + OpamFilename.Dir.to_string (OpamPath.Switch.root root switch), + Some "Prefix of the current opam switch") :: + List.filter (function ("OPAM_SWITCH_PREFIX", Eq, _, _) -> false | _ -> true) + upd + in let upd = if force_path then List.map (function