open Http_getter_types
exception Not_found'
-exception Resource_not_found of string (** uri *)
+exception Resource_not_found of string * string (** method, uri *)
let index_fname = "INDEX"
with Unix.Unix_error (_, "opendir", _) -> []
let ls_http_single _ url_prefix =
- let index = Http_getter_wget.get (normalize_dir url_prefix ^ index_fname) in
- Pcre.split ~rex:newline_RE index
+ try
+ let index = Http_getter_wget.get (normalize_dir url_prefix ^ index_fname) in
+ Pcre.split ~rex:newline_RE index
+ with Http_client_error _ -> raise Not_found'
let get_file _ path =
if Sys.file_exists (path ^ gz_suffix) then
| [scheme; path] -> scheme, path
| _ -> assert false
in
- let cache_dest =
+ let cache_name =
sprintf "%s%s/%s" (Lazy.force Http_getter_env.cache_dir) scheme path
in
- if not (Sys.file_exists cache_dest) then begin (* fill cache *)
- Http_getter_misc.mkdir ~parents:true (Filename.dirname cache_dest);
+ if Sys.file_exists (cache_name ^ gz_suffix) then
+ cache_name ^ gz_suffix
+ else if Sys.file_exists cache_name then
+ cache_name
+ else begin (* fill cache *)
+ Http_getter_misc.mkdir ~parents:true (Filename.dirname cache_name);
(try
- Http_getter_wget.get_and_save (url ^ gz_suffix) (cache_dest ^ gz_suffix)
- with Http_user_agent.Http_error _ ->
+ Http_getter_wget.get_and_save (url ^ gz_suffix) (cache_name ^ gz_suffix);
+ cache_name ^ gz_suffix
+ with Http_client_error _ ->
(try
- Http_getter_wget.get_and_save url cache_dest
- with Http_user_agent.Http_error _ ->
+ Http_getter_wget.get_and_save url cache_name;
+ cache_name
+ with Http_client_error _ ->
raise Not_found'))
- end;
- cache_dest
+ end
let remove_file _ path =
if Sys.file_exists (path ^ gz_suffix) then Sys.remove (path ^ gz_suffix);
storage_method.http uri url
else
raise (Unsupported_scheme url)
- with Not_found' -> raise (Resource_not_found uri)
+ with Not_found' -> raise (Resource_not_found (storage_method.name, uri))
let exists =
dispatch { name = "exists"; file = exists_file; http = exists_http }
* for example: when doing "ls cic:/" we would like to see the "cic:/matita"
* directory *)
let ls uri_prefix =
+(* prerr_endline ("Http_getter_storage.ls " ^ uri_prefix); *)
let direct_results = ls_single uri_prefix in
List.fold_left
(fun results (_, uri_prefix', _) ->
* holds: that exception is raised iff exists return false on a given resource
* *)
-exception Resource_not_found of string (** uri *)
+exception Resource_not_found of string * string (** method, uri *)
(** @return a list of string where dir are returned with a trailing "/" *)
val ls: string -> string list
(** @return the filename of the resource corresponding to a given uri. Handle
- * download and caching for remote resources. *)
-val filename: string -> string
+ * download and caching for remote resources.
+ * @param find if set to true all matching prefixes will be searched for the
+ * asked resource, if not only the best matching prefix will be used. Note
+ * that the search is performed only if the asked resource is not found in
+ * cache (i.e. to perform the find again you need to clean the cache).
+ * Defaults to false *)
+val filename: (* ?find:bool -> *) string -> string
(** only works for local resources
* if both compressed and non-compressed versions of a resource exist, both of