source: code/trunk/lib/peers.ml@ 36

Last change on this file since 36 was 31, checked in by fox, 2 years ago

Introduce 'peers' subcommand, refactor in pull

File size: 999 bytes
Line 
1let text_dir = Filename.concat (File_store.txtdir ()) "peers"
2
3type t = { path: string; locations: string list }
4
5let fold fn init = match Sys.readdir text_dir with
6 | exception (Sys_error msg) -> prerr_endline msg; init
7 | dirs ->
8 let read_pack init path =
9 let fullpath = Filename.concat text_dir path in
10 if Sys.is_directory fullpath then begin
11 let pack_path = Filename.concat fullpath "index.pck" in
12 match Sys.file_exists pack_path with
13 | false -> Printf.eprintf "Missing index.pck for %s\n" path; init
14 | true -> match Header_pack.of_string (File_store.to_string pack_path) with
15 | Error s -> Printf.eprintf "%s %s\n" s pack_path; init
16 | Ok p -> fn init { path; locations = Header_pack.(p.info.locations) }
17 end else init
18 in
19 Array.fold_left read_pack init dirs
20
21let scheme url =
22 let colon_idx = String.index_from url 0 ':' in
23 let scheme = String.sub url 0 colon_idx in
24(* let remain = String.(sub url (colon_idx+1) (length url - length scheme - 1)) in*)
25 scheme
Note: See TracBrowser for help on using the repository browser.