[infer][PR] Remove function Utils.write_file_with_locking

Summary:
`Utils.with_intermediate_temp_file_out` is conceptually simpler. Plus,
this removes a dependency on Unix.flock, which is not portable under
Windows.
Pull Request resolved: https://github.com/facebook/infer/pull/1066

Differential Revision: D14208138

Pulled By: jvillard

fbshipit-source-id: 7587007e5
master
Boris Yakobowski 6 years ago committed by Facebook Github Bot
parent 22578089c3
commit c08dffeb36

@ -314,7 +314,7 @@ let report stats_kind file stats_type () =
try
Unix.mkdir_p (Filename.dirname file) ;
(* the same report may be registered across different infer processes *)
Utils.write_file_with_locking file ~f:(fun stats_oc ->
Utils.with_intermediate_temp_file_out file ~f:(fun stats_oc ->
Yojson.Basic.pretty_to_channel stats_oc json_stats )
with exc ->
L.internal_error "Info: failed to write stats to %s@\n%s@\n%s@\n%s@." file

@ -306,24 +306,6 @@ let compare_versions v1 v2 =
[%compare: int list] lv1 lv2
let write_file_with_locking ?(delete = false) ~f:do_write fname =
Unix.with_file
~mode:Unix.[O_WRONLY; O_CREAT]
fname
~f:(fun file_descr ->
if Unix.flock file_descr Unix.Flock_command.lock_exclusive then (
(* make sure we're not writing over some existing, possibly longer content: some other
process may have snagged the file from under us between open(2) and flock(2) so passing
O_TRUNC to open(2) above would not be a good substitute for calling ftruncate(2)
below. *)
Unix.ftruncate file_descr ~len:Int64.zero ;
let outc = Unix.out_channel_of_descr file_descr in
do_write outc ;
Out_channel.flush outc ;
ignore (Unix.flock file_descr Unix.Flock_command.unlock) ) ) ;
if delete then try Unix.unlink fname with Unix.Unix_error _ -> ()
let rec rmtree name =
match Unix.((lstat name).st_kind) with
| S_DIR ->

@ -96,10 +96,6 @@ val compare_versions : string -> string -> int
-1 if v1 is older than v2 and 0 if they are the same version.
The versions are strings of the shape "n.m.t", the order is lexicographic. *)
val write_file_with_locking : ?delete:bool -> f:(Out_channel.t -> unit) -> string -> unit
(** Lock file passed as argument and write into it using [f]. If [delete] then the file is unlinked
once this is done. *)
val rmtree : string -> unit
(** [rmtree path] removes [path] and, if [path] is a directory, recursively removes its contents *)

Loading…
Cancel
Save