+let list_writable_prefixes _ =
+ HExtlib.filter_map
+ (fun (_,_,url,attrs) ->
+ if is_readwrite attrs then
+ Some url
+ else
+ None)
+ (Lazy.force (prefix_map ()))
+
+let is_legacy uri = List.for_all has_legacy (get_attrs uri)
+
+(* implement this in a fast way! *)
+let is_empty buri =
+ let buri = strip_trailing_slash buri ^ "/" in
+ let files = ls buri in
+ is_empty_listing files
+
+let is_read_only uri =
+ let is_empty_dir path =
+ let files =
+ if is_file_schema path then
+ ls_file_single () (path_of_file_url path)
+ else if is_http_schema path then
+ ls_http_single () path
+ else
+ assert false
+ in
+ is_empty_listing files
+ in
+ let rec aux found_writable = function
+ | (rex, _, url_prefix, attrs)::tl ->
+ let new_url = (Pcre.replace_first ~rex ~templ:url_prefix uri) in
+ let rdonly = has_legacy attrs || has_rdonly attrs in
+ (match rdonly, is_empty_dir new_url, found_writable with
+ | true, false, _ -> true
+ | true, true, _ -> aux found_writable tl
+ | false, _, _ -> aux true tl)
+ | [] -> not found_writable (* if found_writable then false else true *)
+ in
+ aux false (lookup uri)
+
+let activate_system_mode () =
+ let map = Lazy.force (prefix_map ()) in
+ let map =
+ HExtlib.filter_map
+ (fun ((rex, urip, urlp, attrs) as entry) ->
+ if has_legacy attrs then
+ Some entry
+ else if has_rdonly attrs then
+ Some (rex, urip, urlp, List.filter ((<>) `Read_only) attrs)
+ else
+ None)
+ map
+ in
+ let map = map in (* just to remember that ocamlc 'lazy' is a ... *)
+ prefix_map_ref := (lazy map)
+
+(* eof *)