Fix writing to file, don't ignore Lwt thread

This commit is contained in:
Stavros Polymenis 2017-11-03 00:12:07 +00:00
parent f7b7cce697
commit c2286d0772

View File

@ -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