summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3b66c43)
use_installed is a global variable (defined in febootstrap_cmdline.mli)
so there's not much point in passing it around to every function that
needs it. This commit removes the optional argument in favour of just
using the global variable in each package handler.
However we still need a place where we can bail if the --use-installed
flag is used for package handlers which don't support this yet.
Thus add a ph_init function is called after the right package handler
has been detected but before it is used. This is a convenient place
to put the --use-installed checking and any other initialization that
is required.
List.flatten (
List.map (
fun pkg ->
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
List.map (fun (filename, ft) -> filename, ft, pkg) files
) packages
) in
* original file from the package.
*)
else if config then (
* 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
(* Note that the output config file might not be a regular file. *)
let statbuf = lstat outfile in
file_exists "/etc/debian_version" &&
Config.aptitude <> "no" && Config.apt_cache <> "no" && Config.dpkg <> "no"
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:]]'"
let rec debian_resolve_dependencies_and_download names =
let cmd =
sprintf "%s depends --recurse -i %s | grep -v '^[<[:space:]]'"
-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. *)
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
if use_installed && List.exists (fun p -> p = pkg) (get_installed_pkgs ())
then
file
let () =
let ph = {
ph_detect = debian_detect;
let () =
let ph = {
ph_detect = debian_detect;
ph_resolve_dependencies_and_download =
debian_resolve_dependencies_and_download;
ph_list_files = debian_list_files;
ph_resolve_dependencies_and_download =
debian_resolve_dependencies_and_download;
ph_list_files = debian_list_files;
type package_handler = {
ph_detect : unit -> bool;
type package_handler = {
ph_detect : unit -> bool;
+ ph_init : unit -> unit;
ph_resolve_dependencies_and_download : string list -> string list;
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;
}
and file_type = {
ft_dir : bool;
+let rec check_system () =
try
handler := Some (
List.find (
fun (_, ph) ->
ph.ph_detect ()
) !handlers
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.
with Not_found ->
eprintf "\
febootstrap: could not detect package manager used by this system or distro.
-let rec get_package_handler () =
+and get_package_handler () =
match !handler with
| Some (_, ph) -> ph
| None ->
check_system ();
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 ->
match !handler with
| Some (name, _) -> name
| None ->
type package_handler = {
ph_detect : unit -> bool;
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]
ph_resolve_dependencies_and_download : string list -> string list;
(** [ph_resolve_dependencies_and_download pkgs]
Note this should also process the [excludes] list. *)
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_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. *)
(** [ph_get_file_from_package pkg file] extracts the
single named file [file] from [pkg]. The path of the
extracted file is returned. *)
file_exists "/etc/arch-release" &&
Config.pacman <> "no"
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"
let pacman_resolve_dependencies_and_download names =
let cmd =
sprintf "(for p in %s; do pactree -u $p; done) | awk '{print $1}' | sort -u"
-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
debug "unpacking %s ..." pkg;
(* We actually need to extract the file in order to get the
files
(* Easy because we already unpacked the archive above. *)
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;
tmpdir // pkg ^ ".d" // file
let () =
let ph = {
ph_detect = pacman_detect;
ph_resolve_dependencies_and_download =
pacman_resolve_dependencies_and_download;
ph_list_files = pacman_list_files;
ph_resolve_dependencies_and_download =
pacman_resolve_dependencies_and_download;
ph_list_files = pacman_list_files;
(file_exists "/etc/redhat-release" || file_exists "/etc/fedora-release") &&
Config.yum <> "no" && Config.rpm <> "no"
(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
let yum_rpm_resolve_dependencies_and_download names =
(* Liberate this data from python. *)
let tmpfile = tmpdir // "names.tmp" in
sprintf "%s/%s-%s-%s.%s.rpm" tmpdir name version release arch
) pkgs
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"
(* Run rpm -qlp with some extra magic. *)
let cmd =
sprintf "rpm -q --qf '[%%{FILENAMES} %%{FILEFLAGS:fflags} %%{FILEMODES} %%{FILESIZES}\\n]' -p %s"
-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
debug "extracting %s from %s ..." file (Filename.basename pkg);
let outfile = tmpdir // file in
let () =
let ph = {
ph_detect = yum_rpm_detect;
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;
ph_resolve_dependencies_and_download =
yum_rpm_resolve_dependencies_and_download;
ph_list_files = yum_rpm_list_files;