Changeset 31 in code for trunk/lib/peers.ml


Ignore:
Timestamp:
Nov 18, 2022, 1:41:55 PM (2 years ago)
Author:
fox
Message:

Introduce 'peers' subcommand, refactor in pull

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/peers.ml

    r21 r31  
    11let text_dir = Filename.concat (File_store.txtdir ()) "peers"
    22
     3type t = { path: string; locations: string list }
     4
    35let fold fn init = match Sys.readdir text_dir with
    4         | exception (Sys_error msg) -> prerr_endline msg
     6        | exception (Sys_error msg) -> prerr_endline msg; init
    57        | dirs ->
    6                 let read_pack path =
    7                         let pack_path = Filename.(concat text_dir @@ concat path "index.pck") in
    8                         match Sys.file_exists pack_path with false -> () | true ->
    9                                 match Header_pack.of_string (File_store.to_string pack_path) with
    10                                 | Error s -> Printf.eprintf "%s %s\n" s pack_path
    11                                 | Ok p -> ignore @@ List.fold_left fn init Header_pack.(p.info.locations)
     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
    1218                in
    13                 Array.iter read_pack dirs
     19                Array.fold_left read_pack init dirs
    1420
    1521let scheme url =
Note: See TracChangeset for help on using the changeset viewer.