Use txt.conf to generate index.pck meta; fix double load while indexing
This commit is contained in:
parent
a8e7281118
commit
4ea44dd16c
12
cli/index.ml
12
cli/index.ml
|
@ -63,17 +63,9 @@ let index r print title auth locs peers =
|
|||
else (File_store.file r.index_path (Header_pack.string pack))
|
||||
|
||||
let load dir =
|
||||
let kv = File_store.of_kv_file () in
|
||||
let index_path = Filename.concat dir "index.pck" in
|
||||
let pck = match Header_pack.of_string @@ File_store.to_string index_path with
|
||||
| Error s -> failwith s | Ok pck -> pck
|
||||
| exception (Sys_error _) -> Header_pack.{
|
||||
info = { version = version; id = Id.generate (); title = ""; people = []; locations = [] };
|
||||
fields;
|
||||
texts = of_text_list @@ File_store.fold ~dir
|
||||
(fun a (t,_) -> of_text a t) [];
|
||||
peers = Msgpck.of_list [];
|
||||
} in
|
||||
index { dir; index_path; pck }
|
||||
index { dir; index_path; pck = Header_pack.of_kv kv }
|
||||
|
||||
open Cmdliner
|
||||
let term =
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
let targets () =
|
||||
let kv = Logarion.File_store.of_kv_file () in
|
||||
let targets kv =
|
||||
let pub_dir =
|
||||
try Logarion.Store.KV.find "Pubdir" kv with Not_found ->
|
||||
try Sys.getenv "txtpubdir" with Not_found -> ""
|
||||
|
@ -13,8 +12,9 @@ let targets () =
|
|||
|
||||
open Logarion
|
||||
let publish ids =
|
||||
let kv = Logarion.File_store.of_kv_file () in
|
||||
let predicate t = List.mem t.Text.id ids in
|
||||
let targets = targets () in
|
||||
let targets = targets kv in
|
||||
let pub_dirs = List.map (fun x -> snd x) targets in
|
||||
File_store.iter ~predicate (fun (_t, p) ->
|
||||
try File.file ((List.hd p)::pub_dirs)
|
||||
|
|
|
@ -53,6 +53,17 @@ let unpack = function
|
|||
|
||||
let of_string s = unpack @@ snd @@ Msgpck.StringBuf.read s
|
||||
|
||||
let of_kv kv =
|
||||
let find k kv = try Store.KV.find k kv with Not_found -> "" in
|
||||
let find_ls k kv = try String_set.list_of_csv (Store.KV.find k kv) with Not_found -> [] in
|
||||
{
|
||||
info = { version = version; id = find "Id" kv; title = find "Title" kv;
|
||||
people = find_ls "Authors" kv; locations = find_ls "Locations" kv };
|
||||
fields;
|
||||
texts = Msgpck.List [];
|
||||
peers = str_list (find_ls "Peers" kv);
|
||||
}
|
||||
|
||||
let list filename = try
|
||||
let texts_list = function
|
||||
| Msgpck.List (_info :: _fields :: [texts]) -> Msgpck.to_list texts
|
||||
|
|
Loading…
Reference in New Issue