<[email protected]> ha escrit: > It would be nice to have saved keyword-values as a variables in the > environment of that <external_program> (like other stuff: TAR_MTIME, > TAR_ATIME,...). > Is it real?
Yes, it is possible. Please try the attached patch (built against current git HEAD). Regards, Sergey
>From 5bdf1f93ce98a46475b5e1ad3db0a9f3b4dbaa44 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff <[email protected]> Date: Tue, 25 Feb 2014 16:16:36 +0200 Subject: [PATCH] Pass extended global headers to the environment of --to-command and --checkpoint * NEWS: Update. * doc/tar.1: Document TAR_HEADER_ envars. * doc/tar.texi: Likewise. * src/common.h (xheader_iterate_global): New prototype. * src/system.c (stat_to_env): Call xheader_iterate_global to pass global headers to the environment. * src/xheader.c (xheader_iterate_global): New function. --- NEWS | 11 +++++++++-- doc/tar.1 | 13 +++++++++++-- doc/tar.texi | 14 ++++++++++++++ src/common.h | 1 + src/system.c | 13 +++++++++++++ src/xheader.c | 10 ++++++++++ 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index fa24142..48670ae 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -GNU tar NEWS - User visible changes. 2014-02-21 +GNU tar NEWS - User visible changes. 2014-02-25 Please send GNU tar bug reports to <[email protected]> @@ -67,7 +67,14 @@ speed up archivation. This release includes official tar(1) and rmt(8) manpages. Distribution maintainers are kindly asked to use these instead of the home-made pages they provided so far. - + +* Environment variables for --to-command and --checkpoint options + +In addition to existing tar-specific environment variables, each +global extended header from a PAX archive is converted to a +corresponding variable whose name is constructed by concatenating the +string "TAR_HEADER_" and the original header name. + version 1.27.1 - Sergey Poznyakoff, 2013-11-17 diff --git a/doc/tar.1 b/doc/tar.1 index cd133d9..647f914 100644 --- a/doc/tar.1 +++ b/doc/tar.1 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with this program. If not, see <http://www.gnu.org/licenses/>. -.TH TAR 1 "February 22, 2014" "TAR" "GNU TAR Manual" +.TH TAR 1 "February 25, 2014" "TAR" "GNU TAR Manual" .SH NAME tar \- an archiving utility .SH SYNOPSIS @@ -448,9 +448,18 @@ Format of the archive being processed. One of: .BR posix , .BR ustar , .BR v7 . +.TP .B TAR_SUBCOMMAND A short option (with a leading dash) describing the operation \fBtar\fR is -executing. +executing. +.TP +\fBTAR_HEADER_\fINAME\fR +When processing a POSIX.1-2001 archive that has global extended +headers, each header is converted to a corresponding environment +variable. The variable name is constructed by concatenating the +string +.B TAR_HEADER_ +and the original header name. .RE .SS Handling of file attributes .TP diff --git a/doc/tar.texi b/doc/tar.texi index e3df0c9..dd89ef5 100644 --- a/doc/tar.texi +++ b/doc/tar.texi @@ -4194,6 +4194,13 @@ A short option describing the operation @command{tar} is executing. @item TAR_FORMAT Format of the archive being processed. @xref{Formats}, for a complete list of archive format names. + +@vrindex TAR_HEADER_@var{name}, checkpoint script environment +@item TAR_HEADER_@var{name} +When processing a POSIX.1-2001 archive (@pxref{posix}) that has global +extended headers, each header is converted to a corresponding +environment variable. The variable name is constructed by +concatenating the string @samp{TAR_HEADER_} and the original header name. @end table These environment variables can also be passed as arguments to the @@ -5776,6 +5783,13 @@ Ordinal number of the volume @command{tar} is processing. @item TAR_FORMAT Format of the archive being processed. @xref{Formats}, for a complete list of archive format names. + +@vrindex TAR_HEADER_@var{name}, to-command environment +@item TAR_HEADER_@var{name} +When processing a POSIX.1-2001 archive (@pxref{posix}) that has global +extended headers, each header is converted to a corresponding +environment variable. The variable name is constructed by +concatenating the string @samp{TAR_HEADER_} and the original header name. @end table These variables are defined prior to executing the command, so you can diff --git a/src/common.h b/src/common.h index edf787c..7269a48 100644 --- a/src/common.h +++ b/src/common.h @@ -784,6 +784,7 @@ void update_archive (void); void xheader_decode (struct tar_stat_info *stat); void xheader_decode_global (struct xheader *xhdr); +void xheader_iterate_global (int (*fn) (const char *, const char *)); void xheader_store (char const *keyword, struct tar_stat_info *st, void const *data); void xheader_read (struct xheader *xhdr, union block *header, off_t size); diff --git a/src/system.c b/src/system.c index 9414233..d93fd46 100644 --- a/src/system.c +++ b/src/system.c @@ -672,6 +672,17 @@ chr_to_env (char const *envar, char c) xalloc_die (); } +#define XHDR_PFX_S "TAR_HEADER_" + +static int +hdr_to_env (const char *kw, const char *value) +{ + char *var = xasprintf ("%s%s", XHDR_PFX_S, kw); + str_to_env (var, value); + free (var); + return 0; +} + static void stat_to_env (char *name, char type, struct tar_stat_info *st) { @@ -695,6 +706,8 @@ stat_to_env (char *name, char type, struct tar_stat_info *st) dec_to_env ("TAR_UID", st->stat.st_uid); dec_to_env ("TAR_GID", st->stat.st_gid); + xheader_iterate_global (hdr_to_env); + switch (type) { case 'b': diff --git a/src/xheader.c b/src/xheader.c index c94c6d3..43c8665 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -782,6 +782,16 @@ xheader_decode_global (struct xheader *xhdr) } } +void +xheader_iterate_global (int (*fn) (const char *, const char *)) +{ + struct keyword_list *kp; + for (kp = global_header_override_list; kp; kp = kp->next) + if (fn (kp->pattern, kp->value)) + break; +} + + static void xheader_init (struct xheader *xhdr) { -- 1.7.12.1
