Commit 5afb83e 1 parent 976455a commit 5afb83e Copy full SHA for 5afb83e
File tree 2 files changed +26
-6
lines changed
2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -33,16 +33,20 @@ module Dir = struct
33
33
let equal = String. equal
34
34
35
35
let of_string dirname =
36
+ OpamSystem. (real_path @@ forward_to_back dirname)
37
+
38
+ let of_string_resolved dirname =
39
+ let home = OpamStd.Sys. home () in
40
+ let prefix = " ~" ^ Filename. dir_sep in
36
41
let dirname =
37
- if dirname = " ~" then OpamStd.Sys. home ()
42
+ if dirname = " ~" then home
38
43
else if
39
- OpamStd.String. starts_with ~prefix: ( " ~ " ^ Filename. dir_sep) dirname
44
+ OpamStd.String. starts_with ~prefix dirname
40
45
then
41
- Filename. concat (OpamStd.Sys. home () )
42
- (OpamStd.String. remove_prefix ~prefix: (" ~" ^ Filename. dir_sep) dirname)
46
+ Filename. concat home (OpamStd.String. remove_prefix ~prefix dirname)
43
47
else dirname
44
48
in
45
- OpamSystem. real_path ( OpamSystem. forward_to_back dirname)
49
+ of_string dirname
46
50
47
51
let to_string dirname = dirname
48
52
@@ -188,6 +192,14 @@ let of_string s =
188
192
basename = Base. of_string basename;
189
193
}
190
194
195
+ let of_string_resolved s =
196
+ let dirname = Filename. dirname s in
197
+ let basename = Filename. basename s in
198
+ {
199
+ dirname = Dir. of_string_resolved dirname;
200
+ basename = Base. of_string basename;
201
+ }
202
+
191
203
let dirname t = t.dirname
192
204
193
205
let basename t = t.basename
Original file line number Diff line number Diff line change @@ -24,7 +24,12 @@ module Base: sig
24
24
end
25
25
26
26
(* * Directory names *)
27
- module Dir : OpamStd .ABSTRACT
27
+ module Dir : sig
28
+ include OpamStd. ABSTRACT
29
+
30
+ (* * Resolve tilde (~) into the home directory. *)
31
+ val of_string_resolved : string -> t
32
+ end
28
33
29
34
(* * Return the current working directory *)
30
35
val cwd : unit -> Dir .t
@@ -116,6 +121,9 @@ val create: Dir.t -> Base.t -> t
116
121
as dirname *)
117
122
val of_basename : Base .t -> t
118
123
124
+ (* * Resolve tilde (~) into the home directory. *)
125
+ val of_string_resolved : string -> t
126
+
119
127
(* * Creation from a raw string, without resolving symlinks, etc. *)
120
128
val raw : string -> t
121
129
You can’t perform that action at this time.
0 commit comments