diff --git a/src/irmin-pack/unix/io.ml b/src/irmin-pack/unix/io.ml index 48c2afd60e..8dcf2fb8a0 100644 --- a/src/irmin-pack/unix/io.ml +++ b/src/irmin-pack/unix/io.ml @@ -290,4 +290,14 @@ 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; O_SYNC; O_RSYNC ] default_open_perm + in + Unix.fsync dirfd; + Unix.close dirfd; + Ok () + with Unix.Unix_error (e, s1, s2) -> Error (`Io_misc (e, s1, s2)) end diff --git a/src/irmin-pack/unix/io_intf.ml b/src/irmin-pack/unix/io_intf.ml index 07b41802b3..0520984d07 100644 --- a/src/irmin-pack/unix/io_intf.ml +++ b/src/irmin-pack/unix/io_intf.ml @@ -143,6 +143,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