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

[Libguestfs] [PATCH 06/10] copy-out: new 'excludes' optional argument



Add a new 'excludes' optional argument to copy-out, passing it straight
to tar-out: this way it is possible to exclude files when extracting a
directory from the guest.
---
 generator/actions.ml | 16 ++++++++++++++--
 gobject/Makefile.inc |  2 ++
 lib/copy-in-out.c    | 13 ++++++++++---
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/generator/actions.ml b/generator/actions.ml
index 990eacb..fd6cc9f 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -3437,8 +3437,9 @@ Wildcards cannot be used." };
 
   { defaults with
     name = "copy_out"; added = (1, 29, 24);
-    style = RErr, [Pathname "remotepath"; String "localdir"], [];
+    style = RErr, [Pathname "remotepath"; String "localdir"], [OStringList "excludes"];
     visibility = VPublicNoFish;
+    once_had_no_optargs = true;
     shortdesc = "copy remote files or directories out of an image";
     longdesc = "\
 C<guestfs_copy_out> copies remote files or directories recursively
@@ -3449,7 +3450,18 @@ To download to the current directory, use C<.> as in:
 
  C<guestfs_copy_out> /home .
 
-Wildcards cannot be used." };
+Wildcards cannot be used.
+
+The other optional arguments are:
+
+=over 4
+
+=item C<excludes>
+
+A list of wildcards.  Files are excluded if they match any of the
+wildcards.  Note they are used only if C<remotepath> is a directory.
+
+=back" };
 
   { defaults with
     name = "set_identifier"; added = (1, 31, 14);
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 55a137e..76482f7 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -67,6 +67,7 @@ guestfs_gobject_headers= \
   include/guestfs-gobject/optargs-copy_device_to_file.h \
   include/guestfs-gobject/optargs-copy_file_to_device.h \
   include/guestfs-gobject/optargs-copy_file_to_file.h \
+  include/guestfs-gobject/optargs-copy_out.h \
   include/guestfs-gobject/optargs-cpio_out.h \
   include/guestfs-gobject/optargs-disk_create.h \
   include/guestfs-gobject/optargs-download_blocks.h \
@@ -158,6 +159,7 @@ guestfs_gobject_sources= \
   src/optargs-copy_device_to_file.c \
   src/optargs-copy_file_to_device.c \
   src/optargs-copy_file_to_file.c \
+  src/optargs-copy_out.c \
   src/optargs-cpio_out.c \
   src/optargs-disk_create.c \
   src/optargs-download_blocks.c \
diff --git a/lib/copy-in-out.c b/lib/copy-in-out.c
index a4e39f8..4691ead 100644
--- a/lib/copy-in-out.c
+++ b/lib/copy-in-out.c
@@ -131,8 +131,9 @@ child_setup (guestfs_h *g, void *data)
 }
 
 int
-guestfs_impl_copy_out (guestfs_h *g,
-                       const char *remotepath, const char *localdir)
+guestfs_impl_copy_out_opts (guestfs_h *g,
+                            const char *remotepath, const char *localdir,
+                            const struct guestfs_copy_out_opts_argv *optargs)
 {
   struct stat statbuf;
   int r;
@@ -170,6 +171,7 @@ guestfs_impl_copy_out (guestfs_h *g,
     struct copy_out_child_data data;
     char fdbuf[64];
     int fd;
+    struct guestfs_tar_out_opts_argv tar_optargs = { .bitmask = 0 };
 
     r = guestfs_is_dir (g, remotepath);
     if (r == -1)
@@ -210,7 +212,12 @@ guestfs_impl_copy_out (guestfs_h *g,
 
     snprintf (fdbuf, sizeof fdbuf, "/dev/fd/%d", fd);
 
-    r = guestfs_tar_out (g, remotepath, fdbuf);
+    if (optargs->bitmask & GUESTFS_COPY_OUT_OPTS_EXCLUDES_BITMASK) {
+      tar_optargs.excludes = optargs->excludes;
+      tar_optargs.bitmask |= GUESTFS_TAR_OUT_OPTS_EXCLUDES_BITMASK;
+    }
+
+    r = guestfs_tar_out_opts_argv (g, remotepath, fdbuf, &tar_optargs);
 
     if (close (fd) == -1) {
       perrorf (g, "close (tar-output subprocess)");
-- 
2.9.3


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