View difference between Paste ID: 15sNZPhv and 4tu1BSCA
SHOW: | | - or go back to the newest paste.
1
open Core
2
3
let archive ~src ~dst =
4
  if not (Sys.is_directory src) then failwithf "%s: not a directory" src ();
5
  if Sys.file_exists dst && not (Sys.is_directory dst) then begin
6
    try Unix.unlink dst with _e -> ();
7-
    Unix.mkdir dst
7+
8
  try Unix.mkdir dst with _e -> ();
9
  List.iter (Sys.ls_dir src) ~f:(fun fn ->
10
    let srcf = src ^/ fn and dstf = dst ^/ fn in
11
    if Sys.is_directory srcf then archive ~src:srcf ~dst:dstf
12
    else begin
13
      Out_channel.write_all dstf ~data:(Ezgzip.compress ~level:9 (In_channel.read_all srcf));
14
      let st = Unix.stat srcf in 
15
      Unix.utimes dstf ~access:st.Unix.st_atime ~modif:st.Unix.st_mtime
16
    end)
17
;;  
18
19
let () =
20
  archive ~src:"/a" ~dst:"b"
21
;;