this repo has no description
1open Bos
2module StringSet = Set.Make (String)
3module StringMap = Map.Make (String)
4
5let lines_of_channel ic =
6 let rec inner acc =
7 try
8 let l = input_line ic in
9 inner (l :: acc)
10 with End_of_file -> List.rev acc
11 in
12 inner []
13
14let lines_of_process cmd =
15 match OS.Cmd.(run_out ~err:err_null cmd |> to_lines) with
16 | Ok x -> x
17 | Error (`Msg e) -> failwith ("Error: " ^ e)
18
19let mkdir_p d =
20 let segs =
21 Fpath.segs (Fpath.normalize d) |> List.filter (fun s -> String.length s > 0)
22 in
23 let _ =
24 List.fold_left
25 (fun path seg ->
26 let d = Fpath.(path // v seg) in
27 try
28 Unix.mkdir (Fpath.to_string d) 0o755;
29 d
30 with
31 | Unix.Unix_error (Unix.EEXIST, _, _) -> d
32 | exn -> raise exn)
33 (Fpath.v ".") segs
34 in
35 ()
36
37let write_file filename lines =
38 let dir = fst (Fpath.split_base filename) in
39 mkdir_p dir;
40 let oc = open_out (Fpath.to_string filename) in
41 List.iter (fun line -> Printf.fprintf oc "%s\n" line) lines;
42 close_out oc
43
44let cp src dst =
45 assert (
46 lines_of_process Cmd.(v "cp" % Fpath.to_string src % Fpath.to_string dst)
47 = [])