Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fsync for directory #2132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/irmin-pack/unix/gc_worker.ml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;
metanivek marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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