module HG = Http_getter;;
module UM = UriManager;;
-let cache_of_processed_baseuri = Hashtbl.create 1024
-let one_step_depend suri dbtype dbd =
- let buri =
- try
- UM.buri_of_uri (UM.uri_of_string suri)
- with UM.IllFormedUri _ -> suri
- in
+let strip_xpointer s = Pcre.replace ~pat:"#.*$" s ;;
+
+let safe_buri_of_suri suri =
+ try
+ UM.buri_of_uri (UM.uri_of_string suri)
+ with
+ UM.IllFormedUri _ -> suri
+
+let one_step_depend cache_of_processed_baseuri suri dbtype dbd =
+ let buri = safe_buri_of_suri suri in
if Hashtbl.mem cache_of_processed_baseuri buri then
[]
else
let obj_tbl = MetadataTypes.obj_tbl () in
if HSql.isMysql dbtype dbd then
sprintf ("SELECT source, h_occurrence FROM %s WHERE "
- ^^ "h_occurrence REGEXP '^%s[^/]*$'") obj_tbl buri
+ ^^ "h_occurrence REGEXP '"^^
+ "^%s\\([^/]+\\|[^/]+#xpointer.*\\)$"^^"'")
+ obj_tbl buri
else
- begin
+ begin
sprintf ("SELECT source, h_occurrence FROM %s WHERE "
- ^^ "REGEXP(h_occurrence, '^%s[^/]*$')") obj_tbl buri
- (* implementation with vanilla ocaml-sqlite3
- HLog.debug "Warning SELECT without REGEXP";
- sprintf
- ("SELECT source, h_occurrence FROM %s WHERE " ^^
- "h_occurrence LIKE '%s%%' " ^^ HSql.escape_string_for_like)
- obj_tbl buri*)
- end
+ ^^ "REGEXP(h_occurrence, '"^^
+ "^%s\\([^/]+\\|[^/]+#xpointer.*\\)$"^^"')")
+ obj_tbl buri
+ (* implementation with vanilla ocaml-sqlite3
+ HLog.debug "Warning SELECT without REGEXP";
+ sprintf
+ ("SELECT source, h_occurrence FROM %s WHERE " ^^
+ "h_occurrence LIKE '%s%%' " ^^ HSql.escape_string_for_like)
+ obj_tbl buri*)
+ end
in
try
let rc = HSql.exec dbtype dbd query in
HSql.iter rc (
fun row ->
match row.(0), row.(1) with
- | Some uri, Some occ when Filename.dirname occ = buri ->
- l := uri :: !l
+ | Some uri, Some occ when
+ Filename.dirname (strip_xpointer occ) = buri ->
+ l := uri :: !l
| _ -> ());
let l = List.sort Pervasives.compare !l in
HExtlib.list_uniq l
exn -> raise exn (* no errors should be accepted *)
end
-let safe_buri_of_suri suri =
- try
- UM.buri_of_uri (UM.uri_of_string suri)
- with
- UM.IllFormedUri _ -> suri
-
let db_uris_of_baseuri buri =
let dbd = LibraryDb.instance () in
let dbtype =
in
try
let rc = HSql.exec dbtype dbd query in
- let strip_xpointer s = Pcre.replace ~pat:"#.*$" s in
let l = ref [] in
HSql.iter rc (
fun row ->
match row.(0) with
| Some uri when Filename.dirname (strip_xpointer uri) = buri ->
l := uri :: !l
- | _ ->
- ());
+ | _ -> ());
let l = List.sort Pervasives.compare !l in
HExtlib.list_uniq l
with
exn -> raise exn (* no errors should be accepted *)
;;
-let close_uri_list uri_to_remove =
+let close_uri_list cache_of_processed_baseuri uri_to_remove =
let dbd = LibraryDb.instance () in
let dbtype =
if Helm_registry.get_bool "matita.system" then HSql.Library else HSql.User
(* now we want the list of all uri that depend on them *)
let depend =
List.fold_left
- (fun acc u -> one_step_depend u dbtype dbd @ acc) [] uri_to_remove
+ (fun acc u -> one_step_depend cache_of_processed_baseuri u dbtype dbd @ acc)
+ [] uri_to_remove
in
let depend =
HExtlib.list_uniq (List.fast_sort Pervasives.compare depend)
in
uri_to_remove, depend
+;;
-let rec close_db uris next =
+let rec close_db cache_of_processed_baseuri uris next =
match next with
| [] -> uris
- | l -> let uris, next = close_uri_list l in close_db uris next @ uris
+ | l ->
+ let uris, next = close_uri_list cache_of_processed_baseuri l in
+ close_db cache_of_processed_baseuri uris next @ uris
+;;
let cleaned_no = ref 0;;
| _ -> assert false)
(Helm_registry.get_list Helm_registry.string "getter.prefix"))
in
- String.sub url 7 (String.length url - 7) (* remove heading "file:///" *)
-)
+ String.sub url 7 (String.length url - 7))
+;;
let clean_baseuris ?(verbose=true) buris =
+ let cache_of_processed_baseuri = Hashtbl.create 1024 in
let dbd = LibraryDb.instance () in
let dbtype =
if Helm_registry.get_bool "matita.system" then HSql.Library else HSql.User
debug_prerr "clean_baseuris called on:";
if debug then
List.iter debug_prerr buris;
- let l = close_db [] buris in
+ let l = close_db cache_of_processed_baseuri [] buris in
let l = HExtlib.list_uniq (List.fast_sort Pervasives.compare l) in
let l = List.map UriManager.uri_of_string l in
debug_prerr "clean_baseuri will remove:";
+++ /dev/null
-H=@
-
-RT_BASEDIR=../
-OPTIONS=-bench -onepass -system
-MMAKE=$(RT_BASEDIR)matitamake $(OPTIONS)
-CLEAN=$(RT_BASEDIR)matitaclean $(OPTIONS)
-MMAKEO=$(RT_BASEDIR)matitamake.opt $(OPTIONS)
-CLEANO=$(RT_BASEDIR)matitaclean.opt $(OPTIONS)
-
-devel:=$(shell basename `pwd`)
-
-ifneq "$(SRC)" ""
- XXX="SRC=$(SRC)"
-endif
-
-all: preall
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKE) build $(devel)
-clean: preall
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKE) clean $(devel)
-cleanall: preall
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MCLEAN) all
-
-all.opt opt: preall.opt
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKEO) build $(devel)
-clean.opt: preall.opt
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKEO) clean $(devel)
-cleanall.opt: preall.opt
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MCLEANO) all
-
-%.mo: preall
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKE) $@
-%.mo.opt: preall.opt
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKEO) $(@:.opt=)
-
-preall:
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKE) init $(devel)
-
-preall.opt:
- $(H)$(XXX) MATITA_FLAGS=$(MATITA_FLAGS) $(MMAKEO) init $(devel)