diff options
-rw-r--r-- | src/febootstrap.ml | 4 | ||||
-rw-r--r-- | src/febootstrap_debian.ml | 8 | ||||
-rw-r--r-- | src/febootstrap_package_handlers.ml | 14 | ||||
-rw-r--r-- | src/febootstrap_package_handlers.mli | 13 | ||||
-rw-r--r-- | src/febootstrap_pacman.ml | 15 | ||||
-rw-r--r-- | src/febootstrap_yum_rpm.ml | 15 |
6 files changed, 40 insertions, 29 deletions
diff --git a/src/febootstrap.ml b/src/febootstrap.ml index 3afb1bb..7e48206 100644 --- a/src/febootstrap.ml +++ b/src/febootstrap.ml @@ -67,7 +67,7 @@ let () = List.flatten ( List.map ( fun pkg -> - let files = ph.ph_list_files ~use_installed pkg in + let files = ph.ph_list_files pkg in List.map (fun (filename, ft) -> filename, ft, pkg) files ) packages ) in @@ -320,7 +320,7 @@ let () = * original file from the package. *) else if config then ( - let outfile = ph.ph_get_file_from_package ~use_installed pkg path in + let outfile = ph.ph_get_file_from_package pkg path in (* Note that the output config file might not be a regular file. *) let statbuf = lstat outfile in diff --git a/src/febootstrap_debian.ml b/src/febootstrap_debian.ml index e7fcffd..e4b42af 100644 --- a/src/febootstrap_debian.ml +++ b/src/febootstrap_debian.ml @@ -45,6 +45,9 @@ let debian_detect () = file_exists "/etc/debian_version" && Config.aptitude <> "no" && Config.apt_cache <> "no" && Config.dpkg <> "no" +let debian_init () = + () + let rec debian_resolve_dependencies_and_download names = let cmd = sprintf "%s depends --recurse -i %s | grep -v '^[<[:space:]]'" @@ -191,14 +194,14 @@ let debian_list_files_installed pkg = ) lines in files -let debian_list_files ?(use_installed=false) pkg = +let debian_list_files pkg = if use_installed && List.exists ((=) pkg) (get_installed_pkgs ()) then debian_list_files_installed pkg else debian_list_files_downloaded pkg (* Easy because we already unpacked the archive above. *) -let debian_get_file_from_package ?(use_installed=false) pkg file = +let debian_get_file_from_package pkg file = if use_installed && List.exists (fun p -> p = pkg) (get_installed_pkgs ()) then file @@ -208,6 +211,7 @@ let debian_get_file_from_package ?(use_installed=false) pkg file = let () = let ph = { ph_detect = debian_detect; + ph_init = debian_init; ph_resolve_dependencies_and_download = debian_resolve_dependencies_and_download; ph_list_files = debian_list_files; diff --git a/src/febootstrap_package_handlers.ml b/src/febootstrap_package_handlers.ml index f627d2f..0d5cc72 100644 --- a/src/febootstrap_package_handlers.ml +++ b/src/febootstrap_package_handlers.ml @@ -24,9 +24,10 @@ open Febootstrap_cmdline type package_handler = { ph_detect : unit -> bool; + ph_init : unit -> unit; ph_resolve_dependencies_and_download : string list -> string list; - ph_list_files : ?use_installed:bool -> string -> (string * file_type) list; - ph_get_file_from_package : ?use_installed:bool -> string -> string -> string + ph_list_files : string -> (string * file_type) list; + ph_get_file_from_package : string -> string -> string } and file_type = { ft_dir : bool; @@ -46,14 +47,15 @@ let register_package_handler name ph = let handler = ref None -let check_system () = +let rec check_system () = try handler := Some ( List.find ( fun (_, ph) -> ph.ph_detect () ) !handlers - ) + ); + (get_package_handler ()).ph_init () with Not_found -> eprintf "\ febootstrap: could not detect package manager used by this system or distro. @@ -65,14 +67,14 @@ then it may be that the package detection code is not working. "; exit 1 -let rec get_package_handler () = +and get_package_handler () = match !handler with | Some (_, ph) -> ph | None -> check_system (); get_package_handler () -let rec get_package_handler_name () = +and get_package_handler_name () = match !handler with | Some (name, _) -> name | None -> diff --git a/src/febootstrap_package_handlers.mli b/src/febootstrap_package_handlers.mli index ebf0386..88916ad 100644 --- a/src/febootstrap_package_handlers.mli +++ b/src/febootstrap_package_handlers.mli @@ -20,7 +20,14 @@ type package_handler = { ph_detect : unit -> bool; - (** Detect if the current system uses this package manager. *) + (** Detect if the current system uses this package manager. This is + called in turn on each package handler, until one returns [true]. *) + + ph_init : unit -> unit; + (** After a package handler is selected, this function is called + which can optionally do any initialization that is required. + This is only called on the package handler if it has returned + [true] from {!ph_detect}. *) ph_resolve_dependencies_and_download : string list -> string list; (** [ph_resolve_dependencies_and_download pkgs] @@ -31,11 +38,11 @@ type package_handler = { Note this should also process the [excludes] list. *) - ph_list_files : ?use_installed:bool -> string -> (string * file_type) list; + ph_list_files : string -> (string * file_type) list; (** [ph_list_files pkg] lists the files and file metadata in the package called [pkg] (a package file). *) - ph_get_file_from_package : ?use_installed:bool -> string -> string -> string; + ph_get_file_from_package : string -> string -> string; (** [ph_get_file_from_package pkg file] extracts the single named file [file] from [pkg]. The path of the extracted file is returned. *) diff --git a/src/febootstrap_pacman.ml b/src/febootstrap_pacman.ml index bd12f69..7fbb72b 100644 --- a/src/febootstrap_pacman.ml +++ b/src/febootstrap_pacman.ml @@ -32,6 +32,10 @@ let pacman_detect () = file_exists "/etc/arch-release" && Config.pacman <> "no" +let pacman_init () = + if use_installed then + failwith "pacman driver doesn't support --use-installed" + let pacman_resolve_dependencies_and_download names = let cmd = sprintf "(for p in %s; do pactree -u $p; done) | awk '{print $1}' | sort -u" @@ -71,10 +75,7 @@ let pacman_resolve_dependencies_and_download names = List.sort compare pkgs -let pacman_list_files ?(use_installed=false) pkg = - if use_installed then - failwith "pacman driver doesn't support --use-installed"; - +let pacman_list_files pkg = debug "unpacking %s ..." pkg; (* We actually need to extract the file in order to get the @@ -119,15 +120,13 @@ let pacman_list_files ?(use_installed=false) pkg = files (* Easy because we already unpacked the archive above. *) -let pacman_get_file_from_package ?(use_installed=false) pkg file = - if use_installed then - failwith "pacman driver doesn't support --use-installed"; - +let pacman_get_file_from_package pkg file = tmpdir // pkg ^ ".d" // file let () = let ph = { ph_detect = pacman_detect; + ph_init = pacman_init; ph_resolve_dependencies_and_download = pacman_resolve_dependencies_and_download; ph_list_files = pacman_list_files; diff --git a/src/febootstrap_yum_rpm.ml b/src/febootstrap_yum_rpm.ml index 815c5ba..bfda11e 100644 --- a/src/febootstrap_yum_rpm.ml +++ b/src/febootstrap_yum_rpm.ml @@ -32,6 +32,10 @@ let yum_rpm_detect () = (file_exists "/etc/redhat-release" || file_exists "/etc/fedora-release") && Config.yum <> "no" && Config.rpm <> "no" +let yum_rpm_init () = + if use_installed then + failwith "yum_rpm driver doesn't support --use-installed" + let yum_rpm_resolve_dependencies_and_download names = (* Liberate this data from python. *) let tmpfile = tmpdir // "names.tmp" in @@ -172,10 +176,7 @@ if verbose: sprintf "%s/%s-%s-%s.%s.rpm" tmpdir name version release arch ) pkgs -let rec yum_rpm_list_files ?(use_installed=false) pkg = - if use_installed then - failwith "yum_rpm driver doesn't support --use-installed"; - +let rec yum_rpm_list_files pkg = (* Run rpm -qlp with some extra magic. *) let cmd = sprintf "rpm -q --qf '[%%{FILENAMES} %%{FILEFLAGS:fflags} %%{FILEMODES} %%{FILESIZES}\\n]' -p %s" @@ -231,10 +232,7 @@ let rec yum_rpm_list_files ?(use_installed=false) pkg = files -let yum_rpm_get_file_from_package ?(use_installed=false) pkg file = - if use_installed then - failwith "yum_rpm driver doesn't support --use-installed"; - +let yum_rpm_get_file_from_package pkg file = debug "extracting %s from %s ..." file (Filename.basename pkg); let outfile = tmpdir // file in @@ -247,6 +245,7 @@ let yum_rpm_get_file_from_package ?(use_installed=false) pkg file = let () = let ph = { ph_detect = yum_rpm_detect; + ph_init = yum_rpm_init; ph_resolve_dependencies_and_download = yum_rpm_resolve_dependencies_and_download; ph_list_files = yum_rpm_list_files; |