Skip to content

Commit 45e811f

Browse files
committed
use mv in rsync store
1 parent c8d208b commit 45e811f

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

.run-gha-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ opam exec -- dune exec -- obuilder healthcheck --store=btrfs:/btrfs
3434
opam exec -- dune exec -- obuilder healthcheck --store=rsync:/tmp/root
3535
opam exec -- dune exec -- obuilder healthcheck --store=zfs:zfs
3636
opam exec -- dune exec -- ./stress/stress.exe btrfs:/btrfs
37-
opam exec -- dune exec -- ./stress/stress.exe rsync:/tmp/root
37+
# Takes too much space/too long for github action
38+
# opam exec -- dune exec -- ./stress/stress.exe rsync:/tmp/root
3839
opam exec -- dune exec -- ./stress/stress.exe zfs:zfs
3940

4041
# Populate the caches from our own GitHub Actions cache

lib/rsync_store.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ module Rsync = struct
2929

3030
let rsync = [ "rsync"; "-aq" ]
3131

32-
let copy_children ~src ~dst =
33-
let cmd = rsync @ [ Fmt.str "%s/" src; dst ] in
32+
let rename ~src ~dst =
33+
let cmd = [ "mv"; src; dst ] in
34+
Os.sudo cmd
35+
36+
let copy_children ?chown ~src ~dst () =
37+
let chown = match chown with
38+
| Some uid_gid -> [ "--chown"; uid_gid ]
39+
| None -> []
40+
in
41+
let cmd = rsync @ chown @ [ src ^ "/"; dst ] in
3442
Os.ensure_dir dst;
3543
Os.sudo cmd
3644
end
@@ -66,17 +74,16 @@ let build t ?base ~id fn =
6674
let result_tmp = Path.result_tmp t id in
6775
begin match base with
6876
| None -> Rsync.create result_tmp
69-
| Some base -> Rsync.copy_children ~src:(Path.result t base) ~dst:result_tmp
77+
| Some base -> Rsync.copy_children ~src:(Path.result t base) ~dst:result_tmp ()
7078
end
7179
>>= fun () ->
7280
Lwt.try_bind
7381
(fun () -> fn result_tmp)
7482
(fun r ->
7583
begin match r with
76-
| Ok () -> Rsync.copy_children ~src:result_tmp ~dst:result
84+
| Ok () -> Rsync.rename ~src:result_tmp ~dst:result
7785
| Error _ -> Lwt.return_unit
7886
end >>= fun () ->
79-
Rsync.delete result_tmp >>= fun () ->
8087
Lwt.return r
8188
)
8289
(fun ex ->
@@ -120,9 +127,8 @@ let cache ~user t name =
120127
end >>= fun () ->
121128
(* Create writeable clone. *)
122129
let gen = cache.gen in
123-
Rsync.copy_children ~src:snapshot ~dst:tmp >>= fun () ->
124130
let { Obuilder_spec.uid; gid } = user in
125-
Os.sudo ["chown"; Printf.sprintf "%d:%d" uid gid; tmp] >>= fun () ->
131+
Rsync.copy_children ~chown:(Printf.sprintf "%d:%d" uid gid) ~src:snapshot ~dst:tmp () >>= fun () ->
126132
let release () =
127133
Lwt_mutex.with_lock cache.lock @@ fun () ->
128134
begin
@@ -131,10 +137,9 @@ let cache ~user t name =
131137
(* todo: check if it has actually changed. *)
132138
cache.gen <- cache.gen + 1;
133139
Rsync.delete snapshot >>= fun () ->
134-
Rsync.copy_children ~src:tmp ~dst:snapshot
140+
Rsync.rename ~src:tmp ~dst:snapshot
135141
) else Lwt.return_unit
136-
end >>= fun () ->
137-
Rsync.delete tmp
142+
end
138143
in
139144
Lwt.return (tmp, release)
140145

0 commit comments

Comments
 (0)