Commit 3df1e5ec authored by Stephane Glondu's avatar Stephane Glondu

In find_election, look for data on disk

parent adb1d44a
......@@ -23,6 +23,7 @@ open Lwt
open Serializable_builtin_j
open Serializable_j
open Common
open Web_serializable_j
open Web_common
type election_state =
......@@ -72,6 +73,22 @@ let set_auth_config x c =
let ( / ) = Filename.concat
let get_raw_election uuid =
try_lwt
let lines = Lwt_io.lines_of_file (!spool_dir / uuid / "election.json") in
begin match_lwt Lwt_stream.to_list lines with
| x :: _ -> return @@ Some x
| [] -> return_none
end
with _ -> return_none
let get_election_metadata uuid =
try_lwt
Lwt_io.chars_of_file (!spool_dir / uuid / "metadata.json") |>
Lwt_stream.to_string >>= fun x ->
return @@ Some (metadata_of_string x)
with _ -> return_none
let get_election_result uuid =
try_lwt
Lwt_io.chars_of_file (!spool_dir / uuid / "result.json") |>
......
......@@ -20,6 +20,7 @@
(**************************************************************************)
open Serializable_t
open Web_serializable_t
type election_state =
[ `Open
......@@ -39,4 +40,6 @@ val set_partial_decryptions : string -> (int * string) list -> unit Lwt.t
val get_auth_config : string -> (string * (string * string list)) list Lwt.t
val set_auth_config : string -> (string * (string * string list)) list -> unit Lwt.t
val get_raw_election : string -> string option Lwt.t
val get_election_metadata : string -> metadata option Lwt.t
val get_election_result : string -> Yojson.Safe.json result option Lwt.t
......@@ -83,8 +83,17 @@ let web_election_data (raw_election, web_params) =
(module D : WEB_ELECTION_DATA)
let raw_find_election uuid =
lwt x = Ocsipersist.find election_ptable uuid in
return (web_election_data x)
lwt raw_election = Web_persist.get_raw_election uuid in
lwt metadata = Web_persist.get_election_metadata uuid in
match raw_election, metadata with
| Some raw_election, Some metadata ->
let module P = struct
let dir = !spool_dir / uuid
let metadata = metadata
end in
let web_params = (module P : WEB_PARAMS) in
return (web_election_data (raw_election, web_params))
| _, _ -> Lwt.fail Not_found
module WCacheTypes = struct
type key = string
......@@ -188,6 +197,9 @@ let import_election f =
Lwt_io.(with_file Output (dir/"voters.txt") (fun oc ->
write_lines oc voters
)) >>
Lwt_io.(with_file Output (dir/"metadata.json") (fun oc ->
write_line oc (string_of_metadata metadata)
)) >>
let election = web_election_data (raw_election, web_params) in
let module W = Web_election.Make ((val election)) (LwtRandom) in
lwt () =
......@@ -1419,3 +1431,14 @@ let () =
Web_persist.set_partial_decryptions uuid_s [1, pd] >>
handle_election_tally_release (uuid, ()) ()
) else Redirection.send (preapply election_admin (uuid, ())))
(** Dump all election metadata to disk at startup (temporary) *)
lwt () =
Ocsipersist.iter_step (fun uuid (_, web_params) ->
let module P = (val web_params : WEB_PARAMS) in
let raw_metadata = string_of_metadata P.metadata in
Lwt_io.(with_file Output (P.dir/"metadata.json") (fun oc ->
write_line oc raw_metadata
))
) election_ptable
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment