Skip to content

Commit

Permalink
fsync dir
Browse files Browse the repository at this point in the history
  • Loading branch information
icristescu committed Nov 9, 2022
1 parent 9127c0c commit 5c7ddf0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/irmin-pack/unix/gc_worker.ml
Expand Up @@ -353,7 +353,8 @@ module Make (Args : Gc_args.S) = struct
let out = Irmin.Type.to_json_string gc_output_t output in
let* () = Io.write_string io ~off:Int63.zero out in
let* () = Io.fsync io in
Io.close io
let* () = Io.close io in
Io.fsync_dir root

(* No one catches errors when this function terminates. Write the result in a
file and terminate. *)
Expand Down
13 changes: 13 additions & 0 deletions src/irmin-pack/unix/io.ml
Expand Up @@ -284,4 +284,17 @@ module Unix = struct
Sys.remove path;
Ok ()
with Sys_error msg -> Error (`Sys_error msg)

let fsync_dir path =
try
let dirfd = Unix.openfile path Unix.[ O_RDONLY ] default_open_perm in
let fsync_result =
try
Unix.fsync dirfd;
Ok ()
with Unix.Unix_error (e, s1, s2) -> Error (`Io_misc (e, s1, s2))
in
Unix.close dirfd;
fsync_result
with Unix.Unix_error (e, s1, s2) -> Error (`Io_misc (e, s1, s2))
end
5 changes: 5 additions & 0 deletions src/irmin-pack/unix/io_intf.ml
Expand Up @@ -140,6 +140,11 @@ module type S = sig

val catch_misc_error :
(unit -> 'a) -> ('a, [> `Io_misc of misc_error ]) result

val fsync_dir : string -> (unit, [> `Io_misc of misc_error ]) result
(** [fsync path] persists to the file system the directory in [path]. Note
that separate fsyncs are needed for persisting the files in the directory
[path]. *)
end

module type Sigs = sig
Expand Down

0 comments on commit 5c7ddf0

Please sign in to comment.