]> Dogcows Code - chaz/tar/blobdiff - src/xheader.c
Bugfix.
[chaz/tar] / src / xheader.c
index aed2eb0cc07b8f43724c8480a66829c03e6abfbf..5eabdfb4318ecaae63b034cfb6138cc2b4868abf 100644 (file)
@@ -1,10 +1,10 @@
 /* POSIX extended headers for tar.
 
 /* POSIX extended headers for tar.
 
-   Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
+   Free Software Foundation; either version 3, or (at your option) any later
    version.
 
    This program is distributed in the hope that it will be useful, but
    version.
 
    This program is distributed in the hope that it will be useful, but
@@ -25,8 +25,6 @@
 
 #include "common.h"
 
 
 #include "common.h"
 
-#include <fnmatch.h>
-
 static bool xheader_protected_pattern_p (char const *pattern);
 static bool xheader_protected_keyword_p (char const *keyword);
 static void xheader_set_single_keyword (char *) __attribute__ ((noreturn));
 static bool xheader_protected_pattern_p (char const *pattern);
 static bool xheader_protected_keyword_p (char const *keyword);
 static void xheader_set_single_keyword (char *) __attribute__ ((noreturn));
@@ -98,9 +96,15 @@ static struct keyword_list *global_header_override_list;
 /* Template for the name field of an 'x' type header */
 static char *exthdr_name;
 
 /* Template for the name field of an 'x' type header */
 static char *exthdr_name;
 
+static char *exthdr_mtime_option;
+static time_t exthdr_mtime;
+
 /* Template for the name field of a 'g' type header */
 static char *globexthdr_name;
 
 /* Template for the name field of a 'g' type header */
 static char *globexthdr_name;
 
+static char *globexthdr_mtime_option;
+static time_t globexthdr_mtime;
+
 bool
 xheader_keyword_deleted_p (const char *kw)
 {
 bool
 xheader_keyword_deleted_p (const char *kw)
 {
@@ -158,6 +162,21 @@ xheader_set_single_keyword (char *kw)
   USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet implemented"), kw));
 }
 
   USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet implemented"), kw));
 }
 
+static void
+assign_time_option (char **sval, time_t *tval, const char *input)
+{
+  uintmax_t u;
+  char *p;
+  time_t t = u = strtoumax (input, &p, 10);
+  if (t != u || *p || errno == ERANGE)
+    ERROR ((0, 0, _("Time stamp is out of allowed range")));
+  else
+    {
+      *tval = t;
+      assign_string (sval, input);
+    }
+}
+
 static void
 xheader_set_keyword_equal (char *kw, char *eq)
 {
 static void
 xheader_set_keyword_equal (char *kw, char *eq)
 {
@@ -170,12 +189,12 @@ xheader_set_keyword_equal (char *kw, char *eq)
       global = false;
     }
 
       global = false;
     }
 
-  while (p > kw && isspace (*p))
+  while (p > kw && isspace ((unsigned char) *p))
     p--;
 
   *p = 0;
 
     p--;
 
   *p = 0;
 
-  for (p = eq + 1; *p && isspace (*p); p++)
+  for (p = eq + 1; *p && isspace ((unsigned char) *p); p++)
     ;
 
   if (strcmp (kw, "delete") == 0)
     ;
 
   if (strcmp (kw, "delete") == 0)
@@ -188,6 +207,10 @@ xheader_set_keyword_equal (char *kw, char *eq)
     assign_string (&exthdr_name, p);
   else if (strcmp (kw, "globexthdr.name") == 0)
     assign_string (&globexthdr_name, p);
     assign_string (&exthdr_name, p);
   else if (strcmp (kw, "globexthdr.name") == 0)
     assign_string (&globexthdr_name, p);
+  else if (strcmp (kw, "exthdr.mtime") == 0)
+    assign_time_option (&exthdr_mtime_option, &exthdr_mtime, p);
+  else if (strcmp (kw, "globexthdr.mtime") == 0)
+    assign_time_option (&globexthdr_mtime_option, &globexthdr_mtime, p);
   else
     {
       if (xheader_protected_keyword_p (kw))
   else
     {
       if (xheader_protected_keyword_p (kw))
@@ -366,14 +389,26 @@ xheader_ghdr_name (void)
 }
 
 void
 }
 
 void
-xheader_write (char type, char *name, struct xheader *xhdr)
+xheader_write (char type, char *name, time_t t, struct xheader *xhdr)
 {
   union block *header;
   size_t size;
   char *p;
 
   size = xhdr->size;
 {
   union block *header;
   size_t size;
   char *p;
 
   size = xhdr->size;
-  header = start_private_header (name, size);
+  switch (type)
+    {
+    case XGLTYPE:
+      if (globexthdr_mtime_option)
+       t = globexthdr_mtime;
+      break;
+
+    case XHDTYPE:
+      if (exthdr_mtime_option)
+       t = exthdr_mtime;
+      break;
+    }
+  header = start_private_header (name, size, t);
   header->header.typeflag = type;
 
   simple_finish_header (header);
   header->header.typeflag = type;
 
   simple_finish_header (header);
@@ -415,7 +450,7 @@ xheader_write_global (struct xheader *xhdr)
   for (kp = keyword_global_override_list; kp; kp = kp->next)
     code_string (kp->value, kp->pattern, xhdr);
   xheader_finish (xhdr);
   for (kp = keyword_global_override_list; kp; kp = kp->next)
     code_string (kp->value, kp->pattern, xhdr);
   xheader_finish (xhdr);
-  xheader_write (XGLTYPE, name = xheader_ghdr_name (), xhdr);
+  xheader_write (XGLTYPE, name = xheader_ghdr_name (), time (NULL), xhdr);
   free (name);
 }
 
   free (name);
 }
 
@@ -573,8 +608,9 @@ decx (void *data, char const *keyword, char const *value, size_t size)
   if (t)
     t->decoder (st, keyword, value, size);
   else
   if (t)
     t->decoder (st, keyword, value, size);
   else
-    WARN((0, 0, _("Ignoring unknown extended header keyword `%s'"),
-        keyword));
+    WARNOPT (WARN_UNKNOWN_KEYWORD,
+            (0, 0, _("Ignoring unknown extended header keyword `%s'"),
+             keyword));
 }
 
 void
 }
 
 void
This page took 0.024766 seconds and 4 git commands to generate.