File tree Expand file tree Collapse file tree 3 files changed +15
-11
lines changed
Expand file tree Collapse file tree 3 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -357,17 +357,11 @@ module File_ops_real (W : sig
357357 ;;
358358
359359 let mkdir_p p =
360- (* CR-someday amokhov: We should really change [Path.mkdir_p dir] to fail if
361- it turns out that [dir] exists and is not a directory. Even better, make
362- [Path.mkdir_p] return an explicit variant to deal with. *)
363- match Fpath. mkdir_p (Path. to_string p) with
364- | `Created -> ()
365- | `Already_exists ->
366- (match Path. is_directory p with
367- | true -> ()
368- | false ->
369- User_error. raise
370- [ Pp. textf " Please delete file %s manually." (Path. to_string_maybe_quoted p) ])
360+ match Fpath. mkdir_p_strict (Path. to_string p) with
361+ | `Created | `Already_exists -> ()
362+ | `Not_a_dir ->
363+ User_error. raise
364+ [ Pp. textf " Please delete file %s manually." (Path. to_string_maybe_quoted p) ]
371365 ;;
372366end
373367
Original file line number Diff line number Diff line change @@ -57,6 +57,15 @@ let rec mkdir_p ?perms t_s =
5757 Code_error. raise " failed to create parent directory" [ " t_s" , Dyn. string t_s ]))
5858;;
5959
60+ let mkdir_p_strict ?perms t_s =
61+ match mkdir_p ?perms t_s with
62+ | `Created -> `Created
63+ | `Already_exists ->
64+ (match (Unix. stat t_s).st_kind with
65+ | S_DIR -> `Already_exists
66+ | _ -> `Not_a_dir )
67+ ;;
68+
6069let link src dst =
6170 match Unix. link src dst with
6271 | exception Unix .Unix_error (Unix. EUNKNOWNERR - 1142 , syscall, arg)
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ type mkdir_p_result =
1616
1717val dyn_of_mkdir_p_result : mkdir_p_result -> Dyn .t
1818val mkdir_p : ?perms : int -> string -> mkdir_p_result
19+ val mkdir_p_strict : ?perms : int -> string -> [ mkdir_p_result | `Not_a_dir ]
1920
2021(* * [link src dst] creates a hardlink from [src] to [dst]. *)
2122val link : string -> string -> unit
You can’t perform that action at this time.
0 commit comments