From 57cb5a62439cc0e4b59d4d19ee1d7e0ffdb4ba26 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 17 Sep 2014 13:07:24 +0200 Subject: [PATCH] package handlers: add possibility for final teardown Add a ph_fini callback to package handlers, so they can do teardown operations, if needed, at the very end of the supermin run. Currently all of the current package handlers do nothing. --- src/dpkg.ml | 1 + src/package_handler.ml | 5 +++++ src/package_handler.mli | 7 +++++++ src/pacman.ml | 1 + src/rpm.ml | 1 + src/supermin.ml | 4 +++- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/dpkg.ml b/src/dpkg.ml index 1bb3f7f..ddfb03a 100644 --- a/src/dpkg.ml +++ b/src/dpkg.ml @@ -191,6 +191,7 @@ let () = let ph = { ph_detect = dpkg_detect; ph_init = dpkg_init; + ph_fini = (fun () -> ()); ph_package_of_string = dpkg_package_of_string; ph_package_to_string = dpkg_package_to_string; ph_package_name = dpkg_package_name; diff --git a/src/package_handler.ml b/src/package_handler.ml index b1dffc0..64b8f66 100644 --- a/src/package_handler.ml +++ b/src/package_handler.ml @@ -59,6 +59,7 @@ let file_source file = type package_handler = { ph_detect : unit -> bool; ph_init : settings -> unit; + ph_fini : unit -> unit; ph_package_of_string : string -> package option; ph_package_to_string : package -> string; ph_package_name : package -> string; @@ -140,6 +141,10 @@ let rec get_package_handler_name () = | Some (system, packager, _) -> sprintf "%s/%s" system packager | None -> assert false +let package_handler_shutdown () = + let ph = get_package_handler () in + ph.ph_fini () + let get_all_requires pkgs = let ph = get_package_handler () in match ph.ph_get_requires with diff --git a/src/package_handler.mli b/src/package_handler.mli index 7e17981..43b0c08 100644 --- a/src/package_handler.mli +++ b/src/package_handler.mli @@ -99,6 +99,11 @@ type package_handler = { initializes. The [settings] parameter is a struct of general settings and configuration. *) + ph_fini : unit -> unit; + (** This is called at the end of the supermin processing. It can + be used to do teardown operations for the package handler, + when no more package-related operations are going to be done. *) + ph_package_of_string : string -> package option; (** Convert a string (from user input) into a package object. If the package is not installed or the string is otherwise @@ -172,6 +177,8 @@ val list_package_handlers : unit -> unit val check_system : settings -> unit +val package_handler_shutdown : unit -> unit + val get_package_handler : unit -> package_handler val get_package_handler_name : unit -> string diff --git a/src/pacman.ml b/src/pacman.ml index 8b11ba8..45fb393 100644 --- a/src/pacman.ml +++ b/src/pacman.ml @@ -227,6 +227,7 @@ let () = let ph = { ph_detect = pacman_detect; ph_init = pacman_init; + ph_fini = (fun () -> ()); ph_package_of_string = pacman_package_of_string; ph_package_to_string = pacman_package_to_string; ph_package_name = pacman_package_name; diff --git a/src/rpm.ml b/src/rpm.ml index 1195948..1bd81f4 100644 --- a/src/rpm.ml +++ b/src/rpm.ml @@ -394,6 +394,7 @@ let () = let fedora = { ph_detect = fedora_detect; ph_init = rpm_init; + ph_fini = (fun () -> ()); ph_package_of_string = rpm_package_of_string; ph_package_to_string = rpm_package_to_string; ph_package_name = rpm_package_name; diff --git a/src/supermin.ml b/src/supermin.ml index 0153977..2ee61a9 100644 --- a/src/supermin.ml +++ b/src/supermin.ml @@ -261,7 +261,9 @@ let main () = *) sprintf "( chmod -R +w %s ; rm -rf %s ) 2>/dev/null &" (quote old_outputdir) (quote old_outputdir) in - ignore (Sys.command cmd) + ignore (Sys.command cmd); + + package_handler_shutdown () let () = try main () -- 1.9.3