Skip to content

Commit

Permalink
Add fsync for directory
Browse files Browse the repository at this point in the history
  • Loading branch information
icristescu committed Nov 7, 2022
1 parent f40ce19 commit 56141bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/irmin-pack/unix/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,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
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

0 comments on commit 56141bb

Please sign in to comment.