only use a single commit in rename

This commit is contained in:
Hannes Mehnert 2024-10-28 21:56:53 +01:00
parent 492f57f850
commit eab5511ab7

View file

@ -648,13 +648,6 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
let open Lwt.Infix in let open Lwt.Infix in
remove ?and_commit:t.committed t key >|= Result.map_error to_write_error remove ?and_commit:t.committed t key >|= Result.map_error to_write_error
let rename t ~source ~dest =
(* TODO(dinosaure): optimize it! It was done on the naive way. *)
let open Lwt_result.Infix in
get t source >>= fun contents ->
remove t source >>= fun () ->
set t dest contents
let allocate t key ?last_modified:_ size = let allocate t key ?last_modified:_ size =
let open Lwt.Infix in let open Lwt.Infix in
exists t key >>= function exists t key >>= function
@ -714,4 +707,18 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
Lwt.wakeup_later wk () ; Lwt.wakeup_later wk () ;
t.committed <- None ; t.committed <- None ;
Lwt.return res Lwt.return res
let rename t ~source ~dest =
let open Lwt_result.Infix in
let op t =
get t source >>= fun contents ->
remove t source >>= fun () ->
set t dest contents
in
match t.committed with
| Some _ -> op t
| None ->
change_and_push t op >>! function
| Ok a -> Lwt.return a
| Error _ as e -> Lwt.return e
end end