[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/2 febootstrap] Collect the size (ft_size) of files from package handlers.



-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
>From fb6a900047ba372ec933ebf1b3d7339c4f33243c Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones redhat com>
Date: Fri, 18 Mar 2011 14:53:04 +0000
Subject: [PATCH 1/2] Collect the size (ft_size) of files from package handlers.

---
 febootstrap.ml                   |    9 +++++----
 febootstrap_debian.ml            |    2 +-
 febootstrap_package_handlers.ml  |    1 +
 febootstrap_package_handlers.mli |    1 +
 febootstrap_pacman.ml            |    2 +-
 febootstrap_yum_rpm.ml           |   13 ++++++++-----
 6 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/febootstrap.ml b/febootstrap.ml
index 9ea9885..3c634c4 100644
--- a/febootstrap.ml
+++ b/febootstrap.ml
@@ -126,7 +126,8 @@ let () =
             else (
               insert_dir parent;
               let newdir = (parent, { ft_dir = true; ft_config = false;
-                                      ft_ghost = false; ft_mode = 0o40755 },
+                                      ft_ghost = false; ft_mode = 0o40755;
+				      ft_size = 0 },
                             "") in
               newdir :: loop parent
             )
@@ -140,12 +141,12 @@ let () =
   if false then (
     List.iter (
       fun (name, { ft_dir = dir; ft_ghost = ghost; ft_config = config;
-                   ft_mode = mode }, pkg) ->
-        printf "%s [%s%s%s%o] from %s\n" name
+                   ft_mode = mode; ft_size = size }, pkg) ->
+        printf "%s [%s%s%s%o %d] from %s\n" name
           (if dir then "dir " else "")
           (if ghost then "ghost " else "")
           (if config then "config " else "")
-          mode
+          mode size
           pkg
     ) files
   );
diff --git a/febootstrap_debian.ml b/febootstrap_debian.ml
index 83c6c1a..f0d0be5 100644
--- a/febootstrap_debian.ml
+++ b/febootstrap_debian.ml
@@ -112,7 +112,7 @@ let debian_list_files pkg =
       let mode = statbuf.st_perm in
 
       (path, { ft_dir = is_dir; ft_config = config; ft_mode = mode;
-	       ft_ghost = false })
+	       ft_ghost = false; ft_size = statbuf.st_size })
   ) lines in
 
   files
diff --git a/febootstrap_package_handlers.ml b/febootstrap_package_handlers.ml
index 72bb172..ad3a233 100644
--- a/febootstrap_package_handlers.ml
+++ b/febootstrap_package_handlers.ml
@@ -33,6 +33,7 @@ and file_type = {
   ft_config : bool;
   ft_ghost : bool;
   ft_mode : int;
+  ft_size : int;
 }
 
 let tmpdir = tmpdir ()
diff --git a/febootstrap_package_handlers.mli b/febootstrap_package_handlers.mli
index 673e448..c28d81f 100644
--- a/febootstrap_package_handlers.mli
+++ b/febootstrap_package_handlers.mli
@@ -50,6 +50,7 @@ and file_type = {
   ft_config : bool;            (** Is a configuration file. *)
   ft_ghost : bool;             (** Is a ghost (created empty) file. *)
   ft_mode : int;               (** File mode. *)
+  ft_size : int;	       (** File size. *)
 }
 
 val register_package_handler : string -> package_handler -> unit
diff --git a/febootstrap_pacman.ml b/febootstrap_pacman.ml
index 760d0ef..96dfefa 100644
--- a/febootstrap_pacman.ml
+++ b/febootstrap_pacman.ml
@@ -111,7 +111,7 @@ let pacman_list_files pkg =
       let mode = statbuf.st_perm in
 
       (path, { ft_dir = is_dir; ft_config = config; ft_mode = mode;
-	       ft_ghost = false })
+	       ft_ghost = false; ft_size = statbuf.st_size })
   ) lines in
 
   files
diff --git a/febootstrap_yum_rpm.ml b/febootstrap_yum_rpm.ml
index e70940d..f6644b8 100644
--- a/febootstrap_yum_rpm.ml
+++ b/febootstrap_yum_rpm.ml
@@ -163,7 +163,7 @@ f.close ()
 let rec yum_rpm_list_files pkg =
   (* Run rpm -qlp with some extra magic. *)
   let cmd =
-    sprintf "rpm -q --qf '[%%{FILENAMES} %%{FILEFLAGS:fflags} %%{FILEMODES}\\n]' -p %s"
+    sprintf "rpm -q --qf '[%%{FILENAMES} %%{FILEFLAGS:fflags} %%{FILEMODES} %%{FILESIZES}\\n]' -p %s"
       pkg in
   let lines = run_command_get_lines cmd in
 
@@ -171,15 +171,16 @@ let rec yum_rpm_list_files pkg =
     filter_map (
       fun line ->
         match string_split " " line with
-        | [filename; flags; mode] ->
+        | [filename; flags; mode; size] ->
             let test_flag = String.contains flags in
             let mode = int_of_string mode in
+	    let size = int_of_string size in
             if test_flag 'd' then None  (* ignore documentation *)
             else
               Some (filename, {
                       ft_dir = mode land 0o40000 <> 0;
                       ft_ghost = test_flag 'g'; ft_config = test_flag 'c';
-                      ft_mode = mode;
+                      ft_mode = mode; ft_size = size;
                     })
         | _ ->
             eprintf "febootstrap: bad output from rpm command: '%s'" line;
@@ -199,7 +200,8 @@ let rec yum_rpm_list_files pkg =
       let dirs =
         List.map (fun name ->
                     name, { ft_dir = true; ft_ghost = false;
-                            ft_config = false; ft_mode = 0o40755 }) dirs in
+                            ft_config = false; ft_mode = 0o40755;
+			    ft_size = 0 }) dirs in
       let devs = [ "/dev/null"; "/dev/full"; "/dev/zero"; "/dev/random";
                    "/dev/urandom"; "/dev/tty"; "/dev/console";
                    "/dev/ptmx"; "/dev/stdin"; "/dev/stdout"; "/dev/stderr" ] in
@@ -207,7 +209,8 @@ let rec yum_rpm_list_files pkg =
       let devs =
         List.map (fun name ->
                     name, { ft_dir = false; ft_ghost = false;
-                            ft_config = false; ft_mode = 0o644 }) devs in
+                            ft_config = false; ft_mode = 0o644;
+			    ft_size = 0 }) devs in
       dirs @ devs @ files
     ) else files in
 
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]