From c2286d0772dd58722216590eeef4886756cacd95 Mon Sep 17 00:00:00 2001 From: Stavros Polymenis Date: Fri, 3 Nov 2017 00:12:07 +0000 Subject: [PATCH] Fix writing to file, don't ignore Lwt thread --- src/store/file.ml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/store/file.ml b/src/store/file.ml index 5a4dbe5..e1ccb3d 100644 --- a/src/store/file.ml +++ b/src/store/file.ml @@ -77,8 +77,10 @@ module Lwt = struct let with_note store new_note = let open Lwt in - let write_note out = Lwt_io.write out (Note.to_string new_note) in - let () = match notepath_with_id store new_note.Note.meta.Meta.uuid with + let open Lwt.Infix in + let store = + let write_note out = Lwt_io.write out (Note.to_string new_note) in + match notepath_with_id store new_note.Note.meta.Meta.uuid with | Some previous_path -> let filepath = let open Note in @@ -87,13 +89,17 @@ module Lwt = struct then Lpath.versioned_basename_of_title store.repo_path new_note.meta.title else previous_path in - ignore_result (Lwt_io.with_file ~mode:Lwt_io.output (Lpath.string_of_note filepath) write_note); - if previous_path <> filepath then ignore_result (Lwt_unix.unlink @@ Lpath.string_of_note previous_path) + Lwt_io.with_file ~mode:Lwt_io.output (Lpath.string_of_note filepath) write_note + >>= (fun () -> + if previous_path <> filepath + then Lwt_unix.unlink @@ Lpath.string_of_note previous_path + else Lwt.return_unit + ) | None -> let filepath = Lpath.versioned_basename_of_title store.repo_path new_note.meta.title in - ignore_result (Lwt_io.with_file ~mode:Lwt_io.output (Lpath.string_of_note filepath) write_note); + Lwt_io.with_file ~mode:Lwt_io.output (Lpath.string_of_note filepath) write_note in - return new_note; + store >>= (fun () -> return new_note); end let with_note = Lwt.with_note