- Timestamp:
- Dec 15, 2022, 9:25:18 PM (2 years ago)
- Location:
- trunk/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/file_store.ml
r32 r42 70 70 let expand_dir d = Array.(to_list @@ map (Filename.concat d) (Sys.readdir d)) in 71 71 let rec loop result = function 72 | f::fs when valid_dir f -> expand_dir f |> List.append fs |> loop result72 | f::fs when valid_dir f -> prerr_endline f; expand_dir f |> List.append fs |> loop result 73 73 | f::fs -> loop (f::result) fs 74 74 | [] -> result in -
trunk/lib/header_pack.ml
r22 r42 11 11 let str = Msgpck.of_string 12 12 let str_list ls = Msgpck.of_list @@ List.map str ls 13 let to_str_list x = List.map Msgpck.to_string (Msgpck.to_list x) 13 let to_str_list x = List.map Msgpck.to_string 14 (try Msgpck.to_list x with e -> prerr_endline "to_str_list"; raise e) 14 15 15 16 let of_set field t = … … 20 21 let to_sec = function Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i | x -> Msgpck.to_uint32 x 21 22 22 let fields = Msgpck.(List [String "id"; String "time"; String "title"; String "authors"; String "topics"]) 23 let fields = Msgpck.(List [ 24 String "id"; String "time"; String "title"; String "authors"; String "topics"; 25 String "references"; String "replies"; 26 ]) 23 27 let to_fields fieldpack = List.map Msgpck.to_string (Msgpck.to_list fieldpack) 24 28 … … 36 40 let open Text in 37 41 Msgpck.(List [ 38 of_id t.id; of_uint32 (date (Date.listing t.date)); 39 String t.title; persons t.authors; List (of_set "topics" t) 42 of_id t.id; 43 of_uint32 (date (Date.listing t.date)); 44 String t.title; 45 persons t.authors; 46 List (of_set "topics" t); 47 List (of_set "references" t); 48 List (of_set "in-reply-to" t); 40 49 ]) :: a 41 50 … … 82 91 let numof_texts pack = List.length (Msgpck.to_list pack.texts) 83 92 84 let iteri fn pack =85 let of_pck i = function Msgpck.List (id::time::title::authors::topics::[]) ->93 let txt_iter_apply fn i = function 94 | Msgpck.List (id::time::title::authors::topics::extra) -> 86 95 let t = match time with Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i 87 96 | x -> Msgpck.to_uint32 x in … … 90 99 let topics = to_str_list topics in 91 100 let authors = to_str_list authors in 92 fn i id t title authors topics 101 let references, replies = 102 try begin match extra with [] -> [], [] 103 | refs::[] -> to_str_list refs, [] 104 | refs::replies::_xs -> to_str_list refs, to_str_list replies 105 end with e -> prerr_endline "iter ref reps"; raise e 106 in 107 fn i id t title authors topics references replies 93 108 | _ -> prerr_endline ("\n\nInvalid record structure\n\n") 94 in List.iteri of_pck (Msgpck.to_list pack.texts);95 109 96 (*let pack_filename ?(filename="index.pck") archive =*) 97 (* let dir = Store.KV.find "Export-Dir" archive.File_store.kv in (*raises Not_found*)*) 98 (* dir ^ "/" ^ filename*) 110 let txt_fold_apply fn i m = 111 (* Printf.eprintf "%s\n%!" @@ Msgpck.show m;*) 112 match m with 113 | Msgpck.List (id::time::title::authors::topics::extra) -> 114 let t = match time with Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i 115 | x -> Msgpck.to_uint32 x in 116 let id = to_id id in 117 let title = Msgpck.to_string title in 118 let topics = try to_str_list topics with _e -> Printf.eprintf "topics %s" title; [] in 119 let authors = try to_str_list authors with _e -> Printf.eprintf "authors %s" title; [] in 120 let references, replies = begin match extra with 121 | [] -> [], [] 122 | refs::[] -> (try to_str_list refs, [] with e -> prerr_endline "fold ref"; raise e) 123 | refs::replies::_xs -> to_str_list refs, to_str_list replies 124 end 125 in 126 fn i id t title authors topics references replies 127 | x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x); i 99 128 100 (*let add archive records =*) 101 (* let fname = pack_filename archive in*) 102 (* let append published (t, _f) = if List.exists (contains t) published then published else to_pack published t in*) 103 (* match list fname with Error e -> prerr_endline e | Ok published_list ->*) 104 (* let header_pack = List.fold_left append published_list records in*) 105 (* let archive = Msgpck.(List [*) 106 (* Int 0; String archive.File_store.name; persons archive.people]) in*) 107 (* File_store.file fname @@ Bytes.to_string*) 108 (* @@ Msgpck.Bytes.to_string (List [archive; fields; Msgpck.List header_pack])*) 129 let iteri fn pack = List.iteri (txt_iter_apply fn) (Msgpck.to_list pack.texts) 130 let fold fn init pack = List.fold_left (txt_fold_apply fn) init 131 (try Msgpck.to_list pack.texts with e -> prerr_string "Pack.fold"; raise e) -
trunk/lib/peers.ml
r31 r42 1 1 let text_dir = Filename.concat (File_store.txtdir ()) "peers" 2 2 3 type t = { path: string; locations: string list }3 type t = { path: string; pack: Header_pack.t } 4 4 5 5 let fold fn init = match Sys.readdir text_dir with … … 14 14 | true -> match Header_pack.of_string (File_store.to_string pack_path) with 15 15 | Error s -> Printf.eprintf "%s %s\n" s pack_path; init 16 | Ok p -> fn init { path; locations = Header_pack.(p.info.locations)}16 | Ok pack -> fn init { path; pack } 17 17 end else init 18 18 in
Note:
See TracChangeset
for help on using the changeset viewer.