[Libguestfs] [PATCH 2/7] tar-out: Add optional numericowner flag (RHBZ#847880).

Richard W.M. Jones rjones at redhat.com
Tue Aug 14 14:51:08 UTC 2012


From: "Richard W.M. Jones" <rjones at redhat.com>

This is equivalent to the tar option --numeric-owner.
---
 daemon/tar.c                   |   14 +++++++++-----
 generator/generator_actions.ml |   15 +++++++++++++--
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/daemon/tar.c b/daemon/tar.c
index 8d78283..f46733d 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -240,7 +240,7 @@ do_txz_in (const char *dir)
 /* Has one FileOut parameter. */
 /* Takes optional arguments, consult optargs_bitmask. */
 int
-do_tar_out (const char *dir, const char *compress)
+do_tar_out (const char *dir, const char *compress, int numericowner)
 {
   const char *filter;
   int r;
@@ -266,9 +266,13 @@ do_tar_out (const char *dir, const char *compress)
   } else
     filter = "";
 
+  if (!(optargs_bitmask & GUESTFS_TAR_OUT_NUMERICOWNER_BITMASK))
+    numericowner = 0;
+
   /* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
-  if (asprintf_nowarn (&cmd, "tar -C %R%s -cf - .",
-                       dir, filter) == -1) {
+  if (asprintf_nowarn (&cmd, "tar -C %R%s%s -cf - .",
+                       dir, filter,
+                       numericowner ? " --numeric-owner" : "") == -1) {
     reply_with_perror ("asprintf");
     return -1;
   }
@@ -321,7 +325,7 @@ int
 do_tgz_out (const char *dir)
 {
   optargs_bitmask = GUESTFS_TAR_OUT_COMPRESS_BITMASK;
-  return do_tar_out (dir, "gzip");
+  return do_tar_out (dir, "gzip", 0);
 }
 
 /* Has one FileOut parameter. */
@@ -329,5 +333,5 @@ int
 do_txz_out (const char *dir)
 {
   optargs_bitmask = GUESTFS_TAR_OUT_COMPRESS_BITMASK;
-  return do_tar_out (dir, "bzip2");
+  return do_tar_out (dir, "bzip2", 0);
 }
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index a29a685..0771b62 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -3433,7 +3433,7 @@ compression types)." };
 
   { defaults with
     name = "tar_out";
-    style = RErr, [String "directory"; FileOut "tarfile"], [OString "compress"];
+    style = RErr, [String "directory"; FileOut "tarfile"], [OString "compress"; OBool "numericowner"];
     proc_nr = Some 70;
     once_had_no_optargs = true;
     cancellable = true;
@@ -3447,7 +3447,18 @@ then the output will be an uncompressed tar file.  Otherwise one
 of the following strings may be given to select the compression
 type of the output file: C<compress>, C<gzip>, C<bzip2>, C<xz>, C<lzop>.
 (Note that not all builds of libguestfs will support all of these
-compression types)." };
+compression types).
+
+The other optional arguments are:
+
+=over 4
+
+=item C<numericowner>
+
+If set to true, the output tar file will contain UID/GID numbers
+instead of user/group names.
+
+=back" };
 
   { defaults with
     name = "tgz_in";
-- 
1.7.10.4




More information about the Libguestfs mailing list