Add additional arguments for tar, so extended attributes and/or SELinux contexts can be saved in output tars. --- daemon/tar.c | 18 +++++++++++++----- generator/actions.ml | 10 +++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/daemon/tar.c b/daemon/tar.c index d6f8f2f..68af749 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -311,7 +311,7 @@ make_exclude_from_file (char *const *excludes) /* Takes optional arguments, consult optargs_bitmask. */ int do_tar_out (const char *dir, const char *compress, int numericowner, - char *const *excludes) + char *const *excludes, int xattrs, int selinux) { CLEANUP_FREE char *buf = NULL; struct stat statbuf; @@ -349,6 +349,12 @@ do_tar_out (const char *dir, const char *compress, int numericowner, return -1; } + if (!(optargs_bitmask & GUESTFS_TAR_OUT_XATTRS_BITMASK)) + xattrs = 0; + + if (!(optargs_bitmask & GUESTFS_TAR_OUT_SELINUX_BITMASK)) + selinux = 0; + /* Check the filename exists and is a directory (RHBZ#908322). */ buf = sysroot_path (dir); if (buf == NULL) { @@ -367,12 +373,14 @@ do_tar_out (const char *dir, const char *compress, int numericowner, } /* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */ - if (asprintf_nowarn (&cmd, "%s -C %Q%s%s%s%s -cf - .", + if (asprintf_nowarn (&cmd, "%s -C %Q%s%s%s%s%s%s -cf - .", str_tar, buf, filter, numericowner ? " --numeric-owner" : "", exclude_from_file ? " -X " : "", - exclude_from_file ? exclude_from_file : "") == -1) { + exclude_from_file ? exclude_from_file : "", + xattrs ? " --xattrs" : "", + selinux ? " --selinux" : "") == -1) { reply_with_perror ("asprintf"); return -1; } @@ -423,7 +431,7 @@ int do_tgz_out (const char *dir) { optargs_bitmask = GUESTFS_TAR_OUT_COMPRESS_BITMASK; - return do_tar_out (dir, "gzip", 0, NULL); + return do_tar_out (dir, "gzip", 0, NULL, 0, 0); } /* Has one FileOut parameter. */ @@ -431,5 +439,5 @@ int do_txz_out (const char *dir) { optargs_bitmask = GUESTFS_TAR_OUT_COMPRESS_BITMASK; - return do_tar_out (dir, "xz", 0, NULL); + return do_tar_out (dir, "xz", 0, NULL, 0, 0); } diff --git a/generator/actions.ml b/generator/actions.ml index 16aeb4b..b336f56 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -4824,7 +4824,7 @@ compression types)." }; { defaults with name = "tar_out"; added = (1, 0, 3); - style = RErr, [String "directory"; FileOut "tarfile"], [OString "compress"; OBool "numericowner"; OStringList "excludes"]; + style = RErr, [String "directory"; FileOut "tarfile"], [OString "compress"; OBool "numericowner"; OStringList "excludes"; OBool "xattrs"; OBool "selinux"]; proc_nr = Some 70; once_had_no_optargs = true; cancellable = true; @@ -4854,6 +4854,14 @@ wildcards. If set to true, the output tar file will contain UID/GID numbers instead of user/group names. +=item C<xattrs> + +If set to true, extended attributes are saved in the output tar. + +=item C<selinux> + +If set to true, SELinux contexts are saved in the output tar. + =back" }; { defaults with -- 2.1.0