Skip to content
Snippets Groups Projects
Commit 1b9e24de authored by Andre Maroneze's avatar Andre Maroneze
Browse files

Merge branch 'feature/nikolai_zeinab/mkdir' into 'master'

[extlib] add function mkdir and fix #425

Closes #425

See merge request frama-c/frama-c!2176
parents 03a9dda9 55c3a5ef
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,6 @@
open Abstract_interp
let pervasives_succ = succ
(* This module uses Bigints everywhere. Set up some notations *)
let pretty_int = Int.pretty
let ( =~ ) = Integer.equal
......
......@@ -325,7 +325,7 @@ struct
let mk_dir d =
try
Unix.mkdir d 0o755;
Extlib.mkdir ~parents:true d 0o755;
L.warning "creating %s directory `%s'" O.option_name d;
d
with Unix.Unix_error _ ->
......
......@@ -343,6 +343,18 @@ let try_finally ~finally f x =
hence interrupting the process, might not work: child processes still need to
run some daemons, such as [flush_all] which is registered by default. *)
let rec mkdir ?(parents=false) name perm =
try Unix.mkdir name perm
with
| Unix.Unix_error (Unix.ENOENT,_,_) when parents ->
let parent_name = Filename.dirname name in
if name <> parent_name then
begin
mkdir ~parents parent_name perm;
Unix.mkdir name perm
end
| e -> raise e
let pid = Unix.getpid ()
let safe_at_exit f =
at_exit
......
......@@ -331,6 +331,17 @@ val try_finally: finally:(unit -> unit) -> ('a -> 'b) -> 'a -> 'b
(** System commands *)
(* ************************************************************************* *)
val mkdir : ?parents:bool -> string -> Unix.file_perm -> unit
(** [mkdir ?parents name perm] creates directory [name] with permission
[perm]. If [parents] is true, recursively create parent directories
if needed. [parents] defaults to false.
Note that this function may create some of the parent directories
and then fail to create the children, e.g. if [perm] does not allow
user execution of the created directory. This will leave the filesystem
in a modified state before raising an exception.
@raise [Unix.Unix_error] if cannot create [name] or its parents.
@since Frama-C+dev *)
val safe_at_exit : (unit -> unit) -> unit
(** Register function to call with [Pervasives.at_exit], but only
for non-child process (fork). The order of execution is preserved
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment