Scripts (especially root.d and extra-data.d) may add new scripts to the
existing set during their execution: in this case, re-read the list of
available scripts, so we do not miss any new addition.
---
dib/dib.ml | 14 +++++++++++++-
dib/elements.ml | 15 +++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/dib/dib.ml b/dib/dib.ml
index 9884a7a..ff2298d 100644
--- a/dib/dib.ml
+++ b/dib/dib.ml
@@ -634,7 +634,19 @@ let main () =
let run_hook ~blockdev ~sysroot ?(new_wd = "") (g : Guestfs.guestfs) hook =
try
- let scripts = Hashtbl.find final_hooks hook in
+ let scripts =
+ (* Sadly, scripts (especially in root.d and extra-data.d)
+ * can add (by copying or symlinking) new scripts for other
+ * phases, which would be ignored if we were using the lists
+ * collected after composing the tree of hooks.
+ * As result, when running in-chroot hooks, re-read the list
+ * of scripts actually available for each hook.
+ *)
+ match hook with
+ | "pre-install.d" | "install.d" | "post-install.d"
| "finalise.d" ->
+ load_scripts g ("/tmp/aux/hooks/" ^ hook)
+ | _ ->
+ Hashtbl.find final_hooks hook in
if debug >= 1 then (
printf "Running hooks for %s...\n%!" hook;
);
diff --git a/dib/elements.ml b/dib/elements.ml
index c6ca0ea..4c2875a 100644
--- a/dib/elements.ml
+++ b/dib/elements.ml
@@ -80,6 +80,21 @@ let load_hooks ~debug path =
) entries;
hooks
+let load_scripts (g : Guestfs.guestfs) path =
+ let listing = Array.to_list (g#readdir path) in
+ let scripts = List.filter (
+ function
+ | { Guestfs.ftyp = ('r'|'l'|'u'|'?') } -> true
+ | _ -> false
+ ) listing in
+ let scripts = List.filter (fun x -> valid_script_name x.Guestfs.name) scripts in
+ filter_map (
+ fun x ->
+ let { Guestfs.st_mode = mode } = g#statns (path ^ "/" ^ x.Guestfs.name)
in
+ if mode &^ 0o111_L > 0_L then Some x.Guestfs.name
+ else None
+ ) scripts
+
let load_elements ~debug paths =
let loaded_elements = Hashtbl.create 13 in
let paths = List.filter is_directory paths in
--
2.9.3