Introduce 'peers' subcommand, refactor in pull

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@31 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
fox
2022-11-18 13:41:55 +00:00
parent 777a1c8aee
commit 215cd434ef
5 changed files with 61 additions and 12 deletions

View File

@@ -1,16 +1,22 @@
let text_dir = Filename.concat (File_store.txtdir ()) "peers"
type t = { path: string; locations: string list }
let fold fn init = match Sys.readdir text_dir with
| exception (Sys_error msg) -> prerr_endline msg
| exception (Sys_error msg) -> prerr_endline msg; init
| dirs ->
let read_pack path =
let pack_path = Filename.(concat text_dir @@ concat path "index.pck") in
match Sys.file_exists pack_path with false -> () | true ->
match Header_pack.of_string (File_store.to_string pack_path) with
| Error s -> Printf.eprintf "%s %s\n" s pack_path
| Ok p -> ignore @@ List.fold_left fn init Header_pack.(p.info.locations)
let read_pack init path =
let fullpath = Filename.concat text_dir path in
if Sys.is_directory fullpath then begin
let pack_path = Filename.concat fullpath "index.pck" in
match Sys.file_exists pack_path with
| false -> Printf.eprintf "Missing index.pck for %s\n" path; init
| true -> match Header_pack.of_string (File_store.to_string pack_path) with
| Error s -> Printf.eprintf "%s %s\n" s pack_path; init
| Ok p -> fn init { path; locations = Header_pack.(p.info.locations) }
end else init
in
Array.iter read_pack dirs
Array.fold_left read_pack init dirs
let scheme url =
let colon_idx = String.index_from url 0 ':' in