Collect the size (ft_size) of files from package handlers.
[febootstrap.git] / febootstrap_package_handlers.ml
1 (* febootstrap 3
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *)
18
19 open Unix
20 open Printf
21
22 open Febootstrap_utils
23 open Febootstrap_cmdline
24
25 type package_handler = {
26   ph_detect : unit -> bool;
27   ph_resolve_dependencies_and_download : string list -> string list;
28   ph_list_files : string -> (string * file_type) list;
29   ph_get_file_from_package : string -> string -> string
30 }
31 and file_type = {
32   ft_dir : bool;
33   ft_config : bool;
34   ft_ghost : bool;
35   ft_mode : int;
36   ft_size : int;
37 }
38
39 let tmpdir = tmpdir ()
40
41 let handlers = ref []
42
43 let register_package_handler name ph =
44   debug "registering package handler: %s" name;
45   handlers := (name, ph) :: !handlers
46
47 let handler = ref None
48
49 let check_system () =
50   try
51     handler := Some (
52       List.find (
53         fun (_, ph) ->
54           ph.ph_detect ()
55       ) !handlers
56     )
57   with Not_found ->
58     eprintf "\
59 febootstrap: could not detect package manager used by this system or distro.
60
61 If this is a new Linux distro, or not Linux, or a Linux distro that uses
62 an unusual packaging format then you may need to port febootstrap.  If
63 you are expecting that febootstrap should work on this system or distro
64 then it may be that the package detection code is not working.
65 ";
66     exit 1
67
68 let rec get_package_handler () =
69   match !handler with
70   | Some (_, ph) -> ph
71   | None ->
72       check_system ();
73       get_package_handler ()
74
75 let rec get_package_handler_name () =
76   match !handler with
77   | Some (name, _) -> name
78   | None ->
79       check_system ();
80       get_package_handler_name ()