@@ -70,24 +70,31 @@ type t = {
70
70
no_depexts : bool ;
71
71
}
72
72
73
+ let win_space_redirection root =
74
+ let redirected = OpamPath. redirected root in
75
+ if OpamFilename. exists redirected then
76
+ OpamFilename.Dir. of_string (OpamFilename. read redirected)
77
+ else root
78
+
79
+ let default_root () =
80
+ (* On Windows, if a .opam directory is found in %HOME% or %USERPROFILE% then
81
+ then we'll use it. Otherwise, we use %LOCALAPPDATA%. *)
82
+ let home_location =
83
+ let open OpamFilename in
84
+ concat_and_resolve (Dir. of_string (OpamStd.Sys. home () )) " .opam"
85
+ in
86
+ if not Sys. win32 || OpamFilename. exists_dir home_location then
87
+ home_location
88
+ else
89
+ let open OpamFilename in
90
+ let local_appdata =
91
+ (* CSIDL_LOCAL_APPDATA = 0x1c *)
92
+ Dir. of_string (OpamStubs. (shGetFolderPath 0x1c SHGFP_TYPE_CURRENT ))
93
+ in
94
+ concat_and_resolve local_appdata " opam"
95
+
73
96
let default = {
74
- root_dir = (
75
- (* On Windows, if a .opam directory is found in %HOME% or %USERPROFILE% then
76
- then we'll use it. Otherwise, we use %LOCALAPPDATA%. *)
77
- let home_location =
78
- let open OpamFilename in
79
- concat_and_resolve (Dir. of_string (OpamStd.Sys. home () )) " .opam"
80
- in
81
- if not Sys. win32 || OpamFilename. exists_dir home_location then
82
- home_location
83
- else
84
- let open OpamFilename in
85
- let local_appdata =
86
- (* CSIDL_LOCAL_APPDATA = 0x1c *)
87
- Dir. of_string (OpamStubs. (shGetFolderPath 0x1c SHGFP_TYPE_CURRENT ))
88
- in
89
- concat_and_resolve local_appdata " opam"
90
- );
97
+ root_dir = default_root () |> win_space_redirection;
91
98
original_root_dir = default_root () ;
92
99
current_switch = None ;
93
100
switch_from = `Default ;
@@ -181,7 +188,7 @@ let initk k =
181
188
| Some s -> Some (OpamSwitch. of_string s), Some `Env
182
189
in
183
190
setk (setk (fun c -> r := c; k)) ! r
184
- ?root_dir:(E. root () >> | OpamFilename.Dir. of_string)
191
+ ?root_dir:(E. root () >> | OpamFilename.Dir. of_string >> | win_space_redirection )
185
192
?original_root_dir:(E. root () >> | OpamFilename.Dir. of_string)
186
193
?current_switch
187
194
?switch_from
@@ -209,6 +216,7 @@ let opamroot ?root_dir () =
209
216
(root_dir >> + fun () ->
210
217
OpamStd.Env. getopt " OPAMROOT" >> | OpamFilename.Dir. of_string)
211
218
+! default.root_dir
219
+ |> win_space_redirection
212
220
213
221
let is_newer_raw = function
214
222
| Some v ->
0 commit comments