···11module Store = Store
2233module History : sig
44+ type mode = Void.mode
45 type post = { diff : Diff.t; time : int64 } [@@deriving repr]
5667 type pre = {
···1920 include Irmin.Contents.S with type t := t
2021end
21222222-include Shelter.Engine.S with type entry = History.t
2323+type action =
2424+ (* Change modes *)
2525+ | Set_mode of History.mode
2626+ (* Fork a new branch from an existing one,
2727+ or switch to a branch if it exists *)
2828+ | Set_session of string
2929+ (* Run a command *)
3030+ | Exec of string list
3131+ (* Undo the last command *)
3232+ | Undo
3333+ (* Replay the current branch onto another *)
3434+ | Replay of string
3535+ (* Display info *)
3636+ | Info of [ `Current | `History ]
3737+ (* Error state *)
3838+ | Unknown of string list
3939+[@@deriving repr]
4040+4141+include Shelter.Engine.S with type entry = History.t and type action := action
+23-11
src/lib/shelter/store.ml
···9494 let exists = Zfs.exists t.zfs (snap :> string) Zfs.Types.snapshot in
9595 if not exists then Zfs.snapshot t.zfs (snap :> string) true
96969797+let destroy t (d : Datasets.dataset) =
9898+ with_dataset t (d :> string) @@ fun ds -> Zfs.destroy ds false
9999+97100let clone t (snap : Datasets.snapshot) (tgt : Datasets.dataset) =
98101 with_dataset ~typ:Zfs.Types.snapshot t (snap :> string) @@ fun src ->
99102 Zfs.clone src (tgt :> string)
···137140 let cid = cid image in
138141 let cids = cid |> Cid.to_string in
139142 let dataset = Datasets.build t.pool cids in
140140- let dir = Eio.Path.(t.fs / ("/" ^ (Datasets.build t.pool cids :> string))) in
141141- create_and_mount t dataset;
142142- let _dir : string = Fetch.get_image ~dir ~proc:t.proc image in
143143- snapshot t (Datasets.snapshot dataset);
144143 let username = Fetch.get_user t.proc image in
145145- ( cid,
146146- Fetch.get_env t.proc image,
147147- get_uid_gid ~username Eio.Path.(dir / "rootfs") )
144144+ let dir = Eio.Path.(t.fs / ("/" ^ (Datasets.build t.pool cids :> string))) in
145145+ if Zfs.exists t.zfs (dataset :> string) Zfs.Types.dataset then
146146+ ( cid,
147147+ Fetch.get_env t.proc image,
148148+ get_uid_gid ~username Eio.Path.(dir / "rootfs") )
149149+ else (
150150+ create_and_mount t dataset;
151151+ let _dir : string = Fetch.get_image ~dir ~proc:t.proc image in
152152+ snapshot t (Datasets.snapshot dataset);
153153+ ( cid,
154154+ Fetch.get_env t.proc image,
155155+ get_uid_gid ~username Eio.Path.(dir / "rootfs") ))
148156149157module Run = struct
150158 let with_build t cid fn =
···193201 (fn (`Exists ("/" ^ (tgt :> string))), diff t src_snap tgt_snap output)
194202 else (
195203 clone t src_snap tgt;
196196- let v = with_build t new_cid fn in
197197- snapshot t tgt_snap;
198198- let d = diff t src_snap tgt_snap output in
199199- (v, d))
204204+ match with_build t new_cid fn with
205205+ | Error _ as v ->
206206+ destroy t tgt;
207207+ (v, [])
208208+ | Ok _ as v ->
209209+ snapshot t tgt_snap;
210210+ let d = diff t src_snap tgt_snap output in
211211+ (v, d))
200212end
+1
vendor/zfs/src/function_description.ml
···4949 (Types.zfs_handle_t @-> string_opt @-> int @-> returning int)
50505151 let close = foreign "zfs_close" (Types.zfs_handle_t @-> returning void)
5252+ let destroy = foreign "zfs_destroy" (Types.zfs_handle_t @-> bool @-> returning int)
5253 let get_type = foreign "zfs_get_type" (Types.zfs_handle_t @-> returning int)
53545455 module Nvlist = struct
+4
vendor/zfs/src/zfs.ml
···9494 let i = C.Functions.create handle path type_ (Nvlist.v props) in
9595 if i != 0 then failwith "Failed to create" else ()
96969797+let destroy handle recurse =
9898+ let i = C.Functions.destroy handle recurse in
9999+ if i != 0 then invalid_arg "destroy" else ()
100100+97101let open_ handle path (type_ : Types.t) = C.Functions.open_ handle path type_
98102let close : t -> unit = C.Functions.close
99103let get_type : t -> Types.t = C.Functions.get_type
+3
vendor/zfs/src/zfs.mli
···7575val close : t -> unit
7676(** Close a dataset *)
77777878+val destroy : t -> bool -> unit
7979+(** Destroy a dataset *)
8080+7881val exists : Handle.t -> string -> Types.t -> bool
7982(** Check if a dataset of a specific type exists *)
8083