module HG = Http_getter;;
module UM = UriManager;;
+let decompile = ref (fun ~baseuri -> assert false);;
+let set_decompile_cb f = decompile := f;;
let strip_xpointer s = Pcre.replace ~pat:"#.*$" s ;;
List.iter (fun u -> debug_prerr (UriManager.string_of_uri u)) l;
List.iter
(fun baseuri ->
+ !decompile ~baseuri;
try
let obj_file =
LibraryMisc.obj_file_of_baseuri ~must_exist:false ~writable:true ~baseuri
storage := sto; aliases := ali; cache := cac
;;
-let path_of_baseuri baseuri =
+let path_of_baseuri ?(no_suffix=false) baseuri =
let uri = NUri.string_of_uri baseuri in
let path = String.sub uri 4 (String.length uri - 4) in
let path = Helm_registry.get "matita.basedir" ^ path in
let dirname = Filename.dirname path in
HExtlib.mkdir dirname;
- path ^ ".ng"
+ if no_suffix then
+ path
+ else
+ path ^ ".ng"
;;
let magic = 0;;
end
let decompile ~baseuri =
- Unix.unlink (path_of_baseuri baseuri)
- (* WE ARE NOT REMOVING ALL THE OBJECTS YET! *)
+ HExtlib.safe_remove (path_of_baseuri baseuri);
+ let basepath = path_of_baseuri ~no_suffix:true baseuri in
+ try
+ let od = Unix.opendir basepath in
+ let rec aux names =
+ try
+ let name = Unix.readdir od in
+ if name <> "." && name <> ".." then aux (name::names) else aux names
+ with
+ End_of_file -> names in
+ let names = List.map (fun name -> basepath ^ "/" ^ name) (aux []) in
+ Unix.closedir od;
+ List.iter Unix.unlink names;
+ HExtlib.rmdir_descend basepath
+ with
+ Unix.Unix_error _ -> () (* raised by Unix.opendir, we hope :-) *)
;;
+LibraryClean.set_decompile_cb
+ (fun ~baseuri -> decompile ~baseuri:(NUri.uri_of_string baseuri));;
+
let fetch_obj uri =
let obj = require0 ~baseuri:uri in
refresh_uri_in_obj obj