Source file commandClean.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
open Ezcmd.TYPES
open EzFile.OP
let cmd_name = "clean"
let clean_log () =
Sys.remove Globals.opambin_log ;
()
let clean_store () =
List.iter (fun dir ->
Printf.eprintf "Cleaning %s\n%!" dir;
Misc.call [| "rm"; "-rf" ; dir |];
EzFile.make_dir ~p:true dir ;
)
[ Globals.opambin_cache_dir ;
Globals.opambin_store_repo_packages_dir ;
Globals.opambin_store_archives_dir ;
];
let store_dir = Globals.opambin_store_dir in
let files = Sys.readdir store_dir in
Array.iter (fun file ->
let packages_dir = store_dir // file // "packages" in
if Sys.file_exists packages_dir then begin
Printf.eprintf "Cleaning %s\n%!" packages_dir;
Misc.call [| "rm" ; "-rf"; packages_dir |];
end
) files;
Misc.call [| "opam"; "update" |];
()
let clean_all () =
clean_log ();
clean_store ();
()
let action args =
match args with
| [] -> clean_all ()
| _ ->
List.iter (function
| "all" -> clean_all ()
| "log" -> clean_log ()
| "store" -> clean_store ()
| s ->
Printf.eprintf "Unexpected argument %S.\n%!" s;
exit 2) args
let cmd =
let anon_args = ref [] in
{
cmd_name ;
cmd_action = (fun () -> action !anon_args) ;
cmd_args = [
[], Arg.Anons (fun list -> anon_args := list),
Ezcmd.info "What to clean (`all`, `log` or `store`)";
];
cmd_man = [];
cmd_doc = "clear all packages and archives from the cache and store";
}