+
+let (/) = Filename.concat
+
+let mkdir_p dir =
+ match Sys.command("mkdir -p " ^ dir) with
+ | 0 -> ()
+ | n ->
+ failwith
+ (sprintf "Failed to create directory: %S. mkdir status: %d\n" dir n)
+
+let gzip path =
+ match Sys.command("gzip " ^ path) with
+ | 0 -> ()
+ | n ->
+ failwith
+ (sprintf "Failed to gzip path: %S. gzip status: %d\n" path n)
+
+let dump_to_dir t ~time ~node ~modul ~dir =
+ (* TODO: Just log the errors and keep it moving, instead of failing. *)
+ mkdir_p dir;
+ let dump_filename = dir / "khatus-cache-dump.psv.gz" in
+ let tmp_filename = "khatus-cache-dump-" ^ (Time.to_string time) in
+ let oc = open_out tmp_filename in
+ dump_to_channel t ~node ~modul ~oc;
+ close_out oc;
+ gzip tmp_filename;
+ Sys.rename (tmp_filename ^ ".gz") dump_filename