Changeset 31 in code


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

Introduce 'peers' subcommand, refactor in pull

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/dune

    r25 r31  
    22 (name txt)
    33 (public_name txt)
    4  (modules txt authors convert conversion edit file index last listing new topics html atom gemini publish pull read recent)
     4 (modules txt authors convert conversion edit file index last listing
     5        new topics html atom gemini peers publish pull read recent)
    56 (libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner))
  • trunk/cli/pull.ml

    r30 r31  
    8787                then pull_text url dir id
    8888
     89(*TODO: integrate in lib*)
    8990let validate_id_length s = String.length s <= 32
    90 
    9191let validate_id_chars s = try
    9292        String.iter (function 'a'..'z'|'A'..'Z'|'0'..'9'-> () | _ -> raise (Invalid_argument "")) s;
     
    9595
    9696let pull_index url authors_opt topics_opt =
    97         let index_url = url ^ "/index.pck" in
     97        let index_url = Filename.concat url "index.pck" in
    9898        match curl_pull index_url with
    9999        | Error s -> prerr_endline s; false
     
    128128        let pull got_one peer_url = if got_one then got_one else
    129129                (pull_index peer_url auths topics) in
    130         Logarion.Peers.fold pull false;
     130        let fold_locations init peer =
     131                ignore @@ List.fold_left pull init peer.Logarion.Peers.locations;
     132                false
     133        in
     134        ignore @@ Logarion.Peers.fold fold_locations false;
    131135        Curl.global_cleanup ()
    132136
  • trunk/cli/txt.ml

    r25 r31  
    1616        Listing.term;
    1717        New.term;
     18        Peers.term;
    1819        Publish.term;
    1920        Pull.term;
  • 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.