help-tar
[Top][All Lists]
Advanced

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

Re: list extended attributes


From: Sergey Poznyakoff
Subject: Re: list extended attributes
Date: Wed, 03 Jun 2020 09:07:46 +0300

Hi Josef,

> i would like to list extended attributes (paxheaders) of a tar-file.
>
> i cannot find documentation (man or info) on how to list that extended
> attributes.

Unfortunately, there isn't any option that would instruct tar to list
extended headers.

> example:
> github embeds git hashes in released tarfiles like
> https://github.com/pymedusa/Medusa/archive/v0.3.16.tar.gz

Github stores commit ids in the "comment" header.  Such headers are
ignored by default.  Perhaps it would be a good idea to optionally
print them too.  If you are interested in it, please try the attached
patch.  It prints the comment headers in the long listing mode (tar vt)
after the file the belong to.

Regards,
Sergey

diff --git a/paxutils b/paxutils
--- a/paxutils
+++ b/paxutils
@@ -1 +1 @@
-Subproject commit 56939847bfa9dbfacb7aebd26f48ea8a64dd8b1d
+Subproject commit 56939847bfa9dbfacb7aebd26f48ea8a64dd8b1d-dirty
diff --git a/src/list.c b/src/list.c
index 3678b29..db82373 100644
--- a/src/list.c
+++ b/src/list.c
@@ -1312,6 +1312,8 @@ simple_print_header (struct tar_stat_info *st, union 
block *blk,
          break;
        }
     }
+  if (st->comment && verbose_option > 1)
+    fprintf (stdlis, " # %s\n", st->comment);
   fflush (stdlis);
   xattrs_print (st);
 }
diff --git a/src/sparse.c b/src/sparse.c
index 08ddb64..e60b16a 100644
--- a/src/sparse.c
+++ b/src/sparse.c
@@ -702,7 +702,7 @@ sparse_diff_file (int fd, struct tar_stat_info *st)
   off_t offset = 0;

   if (!tar_sparse_init (&file))
-    return dump_status_not_implemented;
+    return false;

   file.stat_info = st;
   file.fd = fd;
diff --git a/src/tar.c b/src/tar.c
index 70289a9..156fd97 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -2844,6 +2844,7 @@ tar_stat_destroy (struct tar_stat_info *st)
   free (st->orig_file_name);
   free (st->file_name);
   free (st->link_name);
+  free (st->comment);
   free (st->uname);
   free (st->gname);
   free (st->cntx_name);
diff --git a/src/tar.h b/src/tar.h
index 103177b..c3cb9ad 100644
--- a/src/tar.h
+++ b/src/tar.h
@@ -293,6 +293,8 @@ struct tar_stat_info
                               trailing slash before it was normalized. */
   char *link_name;          /* name of link for the current archive entry.  */

+  char *comment;
+
   char          *uname;     /* user name of owner */
   char          *gname;     /* group name of owner */

diff --git a/src/xheader.c b/src/xheader.c
index d0f43c1..d4cefba 100644
--- a/src/xheader.c
+++ b/src/xheader.c
@@ -1212,6 +1212,16 @@ dummy_decoder (struct tar_stat_info *st __attribute__ 
((unused)),
 }

 static void
+comment_decoder (struct tar_stat_info *st,
+                char const *keyword,
+                char const *arg,
+                size_t size __attribute__((unused)))
+{
+  free (st->comment);
+  st->comment = xstrdup (arg);
+}
+
+static void
 atime_coder (struct tar_stat_info const *st, char const *keyword,
             struct xheader *xhdr, void const *data __attribute__ ((unused)))
 {
@@ -1770,7 +1780,7 @@ sparse_minor_decoder (struct tar_stat_info *st,

 struct xhdr_tab const xhdr_tab[] = {
   { "atime",    atime_coder,    atime_decoder,    0, false },
-  { "comment",  dummy_coder,    dummy_decoder,    0, false },
+  { "comment",  dummy_coder,    comment_decoder,  0, false },
   { "charset",  dummy_coder,    dummy_decoder,    0, false },
   { "ctime",    ctime_coder,    ctime_decoder,    0, false },
   { "gid",      gid_coder,      gid_decoder,      0, false },

reply via email to

[Prev in Thread] Current Thread [Next in Thread]