1 module HGT = Http_getter_types;;
2 module HG = Http_getter;;
3 module HGM = Http_getter_misc;;
4 module UM = UriManager;;
5 module TA = TacticAst;;
7 let baseuri_of_baseuri_decl st =
8 let module TA = TacticAst in
10 | TA.Executable (_, TA.Command (_, TA.Set (_, "baseuri", buri))) ->
14 let cache_of_processed_baseuri = Hashtbl.create 1024
16 let one_step_depend suri =
19 UM.buri_of_uri (UM.uri_of_string suri)
20 with UM.IllFormedUri _ -> suri
22 if Hashtbl.mem cache_of_processed_baseuri buri then
26 Hashtbl.add cache_of_processed_baseuri buri true;
28 let buri = buri ^ "/" in
29 let buri = Mysql.escape buri in
30 let obj_tbl = MetadataTypes.obj_tbl () in
32 "SELECT source, h_occurrence FROM %s WHERE h_occurrence LIKE '%s%%'" obj_tbl buri
35 let rc = Mysql.exec (MatitaDb.instance ()) query in
39 match row.(0), row.(1) with
40 | Some uri, Some occ when Filename.dirname occ = buri ->
43 let l = List.sort Pervasives.compare !l in
44 MatitaMisc.list_uniq l
46 exn -> raise exn (* no errors should be accepted *)
50 let safe_buri_of_suri suri =
52 UM.buri_of_uri (UM.uri_of_string suri)
54 UM.IllFormedUri _ -> suri
56 let close_uri_list uri_to_remove =
57 (* to remove an uri you have to remove the whole script *)
60 (List.fast_sort Pervasives.compare
61 (List.map safe_buri_of_suri uri_to_remove))
63 (* cleand the already visided baseuris *)
67 if Hashtbl.mem cache_of_processed_baseuri buri then false
71 (* now calculate the list of objects that belong to these baseuris *)
75 let inhabitants = HG.ls (buri ^ "/") in
76 let inhabitants = List.filter
77 (function HGT.Ls_object _ -> true | _ -> false)
80 let inhabitants = List.map
82 | HGT.Ls_object e -> buri ^ "/" ^ e.HGT.uri
89 (* now we want the list of all uri that depend on them *)
92 (fun acc u -> one_step_depend u @ acc) [] uri_to_remove
96 (List.fast_sort Pervasives.compare depend)
100 let baseuri_of_file file =
101 let ic = open_in file in
102 let stms = CicTextualParser2.parse_statements (Stream.of_channel ic) in
107 match baseuri_of_baseuri_decl stm with
108 | Some buri -> uri := MatitaMisc.strip_trailing_slash buri
113 let rec fix uris next =
116 | l -> let uris, next = close_uri_list l in fix uris next @ uris
118 let clean_baseuris ?(verbose=true) buris =
119 let buris = List.map HGM.strip_trailing_slash buris in
120 (* List.iter prerr_endline buris; *)
121 let l = fix [] buris in
122 let l = MatitaMisc.list_uniq (List.fast_sort Pervasives.compare l) in
123 let l = List.map UriManager.uri_of_string l in
124 (* List.iter (fun u -> prerr_endline (UriManager.string_of_uri u)) l; *)
125 List.iter (MatitaSync.remove ~verbose) l
127 let is_empty buri = HG.ls (HGM.strip_trailing_slash buri ^ "/") = []