Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Fix Ocaml Plugin problems on OS X (fixes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
trefis committed Mar 15, 2016
1 parent b957f92 commit 2d5e332
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/ocaml_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ end = struct
let extract () =
if_ persistent (fun () ->
let lock_filename = compiler_dir ^ ".lock" in
Shell.mkdir_p ~perm:0o755 (Filename.dirname lock_filename) >>=? fun () ->
Monitor.try_with_or_error (fun () ->
Unix.mkdir ~p:() ~perm:0o755 (Filename.dirname lock_filename)) >>=? fun () ->
Lock_file.Nfs.create lock_filename >>=? fun () ->
archive_lock := Archive_lock.Locked lock_filename;
(* Beware of race condition in here. If we are killed in the middle of rm -rf, but
Expand All @@ -313,7 +314,8 @@ end = struct
delete the info file, then delete everything else. *)
Shell.rm ~f:() [ Info.info_file compiler_dir ] >>=? fun () ->
Shell.rm ~r:() ~f:() [ compiler_dir ] >>=? fun () ->
Shell.mkdir_p ~perm:0o755 compiler_dir
Monitor.try_with_or_error (fun () ->
Unix.mkdir ~p:() ~perm:0o755 compiler_dir)
) >>=? fun () ->
let destination = compiler_dir ^/ tar_id in
save_archive_to destination >>=? fun () ->
Expand Down
6 changes: 4 additions & 2 deletions src/plugin_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ module State = struct
let reset_cache_if_writable info =
if_ (not (Config.readonly t.config)) (fun () ->
let dir = Config.dir t.config ^/ Info.cache_dir in
Shell.mkdir_p ~perm:Info.cache_dir_perm dir >>=? fun () ->
Monitor.try_with_or_error (fun () ->
Unix.mkdir ~p:() ~perm:Info.cache_dir_perm dir) >>=? fun () ->
take_write_lock t >>=? fun () ->
Info.save ~dir:config_dir Info.empty >>=? fun () ->
parallel ~f:Plugin.clean (Info.plugins info) >>=? fun () ->
Expand Down Expand Up @@ -522,7 +523,8 @@ module State = struct
let add t sources plugin_uuid filename =
if_ (not (Config.readonly t.config)) (fun () ->
let dir = Config.dir t.config ^/ Info.cache_dir in
Shell.mkdir_p ~perm:Info.cache_dir_perm dir >>=? fun () ->
Monitor.try_with_or_error (fun () ->
Unix.mkdir ~p:() ~perm:Info.cache_dir_perm dir) >>=? fun () ->
take_write_lock t >>=? fun () ->
let uuid = Plugin_uuid.uuid plugin_uuid in
let cmxs_filename = dir ^/ (Uuid.to_string uuid) ^ ".cmxs" in
Expand Down
9 changes: 3 additions & 6 deletions src/shell.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ let run_lines = make_run ~quiet_or_error:false
)
;;

let mkdir_p ?(perm=permission_exe) path =
run "/bin/mkdir" [ "-p" ; sprintf "-m0%o" perm ; "--" ; path ]
;;

let getcwd () =
Deferred.Or_error.try_with ~name:"Ocaml_plugin.Shell.getcwd" Sys.getcwd
;;
Expand All @@ -131,8 +127,9 @@ let raw_temp_dir ~in_dir ?(prefix="ocaml_plugin_") ?(suffix=".build") () =
prefix
suffix
in
mkdir_p ~perm:permission_exe in_dir >>=? fun () ->
Deferred.Or_error.try_with ~extract_exn:true (fun () -> In_thread.run fct)
Deferred.Or_error.try_with ~extract_exn:true (fun () ->
Unix.mkdir ~p:() ~perm:permission_exe in_dir >>= fun () ->
In_thread.run fct)
;;

let absolute_pathname filename =
Expand Down
2 changes: 0 additions & 2 deletions src/shell.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ val run_lines :
-> string list
-> string list Deferred.Or_error.t

val mkdir_p : ?perm:int -> string -> unit Deferred.Or_error.t

val getcwd : unit -> string Deferred.Or_error.t

val chmod : string -> perm:Unix.file_perm -> unit Deferred.Or_error.t
Expand Down

0 comments on commit 2d5e332

Please sign in to comment.