1 | let split_filetypes files =
|
---|
2 | let acc (dirs, files) x = if Sys.is_directory x
|
---|
3 | then (x::dirs, files) else (dirs, x::files) in
|
---|
4 | List.fold_left acc ([],[]) files
|
---|
5 |
|
---|
6 | open Logarion
|
---|
7 | let file files =
|
---|
8 | let dirs, files = split_filetypes files in
|
---|
9 | let _link_as_named dir file = Unix.link file (Filename.concat dir file) in
|
---|
10 | let link_with_id dir file =
|
---|
11 | match File_store.to_text file with Error s -> prerr_endline s
|
---|
12 | | Ok t -> Unix.link file (Filename.concat dir (Text.short_id t^".txt")) in
|
---|
13 | let link = link_with_id in
|
---|
14 | List.iter (fun d -> List.iter (link d) files) dirs
|
---|
15 |
|
---|
16 | let unfile files =
|
---|
17 | let dirs, files = split_filetypes files in
|
---|
18 | let unlink dir file = try Unix.unlink (Filename.concat dir file)
|
---|
19 | with Unix.(Unix_error(ENOENT,_,_))-> () in
|
---|
20 | List.iter (fun d -> List.iter (unlink d) files) dirs
|
---|
21 |
|
---|
22 | open Cmdliner
|
---|
23 | let term =
|
---|
24 | let files = Arg.(value & pos_all string [] & info []
|
---|
25 | ~docv:"text filenames and subdirectories") in
|
---|
26 | Term.(const file $ files), Term.info "file"
|
---|
27 | ~doc:"file texts in subdirectories"
|
---|
28 | ~man:[ `S "DESCRIPTION"; `P "Files all texts in parameter in every
|
---|
29 | directory in parameter, using hardlinks.
|
---|
30 |
|
---|
31 | Use it to create sub-repositories for sharing or converting" ]
|
---|
32 |
|
---|
33 | let unfile_term =
|
---|
34 | let files = Arg.(value & pos_all string [] & info []
|
---|
35 | ~docv:"text filenames and subdirectories") in
|
---|
36 | Term.(const unfile $ files), Term.info "unfile"
|
---|
37 | ~doc:"unfile texts from subdirectories"
|
---|
38 | ~man:[ `S "DESCRIPTION"; `P "unfile texts in parameter from
|
---|
39 | directories in parameter, by removing hardlinks" ]
|
---|