Commit e4d96c2d authored by Stephane Glondu's avatar Stephane Glondu

Dump ballots at each addition

parent 919b3281
......@@ -128,21 +128,11 @@ module Make (E : ELECTION with type 'a m = 'a Lwt.t) : WEB_BALLOT_BOX = struct
Printf.sprintf "%s attempted to vote with already used credential %s" user credential
) >> fail ReusedCredential
let do_write_ballots () =
Web_persist.dump_ballots uuid
let mutex = Lwt_mutex.create ()
let cast rawballot (user, date) =
Lwt_mutex.with_lock mutex (fun () ->
let%lwt r = do_cast rawballot (user, date) in
do_write_ballots () >>
return r
)
let update_files () =
Lwt_mutex.with_lock mutex (fun () ->
do_write_ballots ()
do_cast rawballot (user, date)
)
end
......@@ -227,15 +227,6 @@ let get_ballot_by_hash uuid hash =
| Some [x] -> return (Some x)
| _ -> return_none
let add_ballot uuid hash ballot =
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
let%lwt () = try%lwt Lwt_unix.mkdir ballots_dir 0o755 with _ -> return_unit in
write_file (ballots_dir / urlize hash) [ballot]
let remove_ballot uuid hash =
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
try%lwt Lwt_unix.unlink (ballots_dir / urlize hash) with _ -> return_unit
let load_ballots uuid =
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
let ballots = Lwt_unix.files_of_directory ballots_dir in
......@@ -250,6 +241,16 @@ let dump_ballots uuid =
let%lwt ballots = load_ballots uuid in
write_file ~uuid "ballots.jsons" ballots
let add_ballot uuid hash ballot =
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
let%lwt () = try%lwt Lwt_unix.mkdir ballots_dir 0o755 with _ -> return_unit in
write_file (ballots_dir / urlize hash) [ballot] >>
dump_ballots uuid
let remove_ballot uuid hash =
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
try%lwt Lwt_unix.unlink (ballots_dir / urlize hash) with _ -> return_unit
let compute_encrypted_tally uuid =
let%lwt election = get_raw_election uuid in
match election with
......
......@@ -66,7 +66,6 @@ val get_ballot_by_hash : uuid -> string -> string option Lwt.t
val add_ballot : uuid -> string -> string -> unit Lwt.t
val remove_ballot : uuid -> string -> unit Lwt.t
val dump_ballots : uuid -> unit Lwt.t
val compute_encrypted_tally : uuid -> (int * string * string) Lwt.t
val find_extended_record : uuid -> string -> (datetime * string) option Lwt.t
......
......@@ -58,5 +58,4 @@ type content =
module type WEB_BALLOT_BOX = sig
val cast : string -> user * datetime -> string Lwt.t
val update_files : unit -> unit Lwt.t
end
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