Merge branch 'dfsg-orig' into dfsg-debian
[debian/tar] / debian / patches / pristine-tar.diff
1 diff --git a/src/common.h b/src/common.h
2 index eb801bb..30f8cf5 100644
3 --- a/src/common.h
4 +++ b/src/common.h
5 @@ -907,4 +907,7 @@ void finish_deferred_unlinks (void);
6  /* Module exit.c */
7  extern void (*fatal_exit_hook) (void);
8  
9 +GLOBAL int debian_longlink_hack;
10 +GLOBAL int pristine_tar_compat;
11 +
12  _GL_INLINE_HEADER_END
13 diff --git a/src/create.c b/src/create.c
14 index e14e13d..d6e8ea7 100644
15 --- a/src/create.c
16 +++ b/src/create.c
17 @@ -27,6 +27,9 @@
18  #include "common.h"
19  #include <hash.h>
20  
21 +extern int debian_longlink_hack;
22 +extern int pristine_tar_compat;
23 +
24  /* Error number to use when an impostor is discovered.
25     Pretend the impostor isn't there.  */
26  enum { IMPOSTOR_ERRNO = ENOENT };
27 @@ -534,6 +537,11 @@ write_short_name (struct tar_stat_info *st)
28    return header;
29  }
30  
31 +#define FILL(field,byte) do {            \
32 +  memset(field, byte, sizeof(field)-1);  \
33 +  (field)[sizeof(field)-1] = 0;          \
34 +} while (0)
35 +
36  /* Write a GNUTYPE_LONGLINK or GNUTYPE_LONGNAME block.  */
37  static void
38  write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
39 @@ -544,6 +552,10 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
40    char *tmpname;
41  
42    header = start_private_header ("././@LongLink", size, start_time.tv_sec);
43 +  if (pristine_tar_compat) {
44 +         FILL (header->header.mtime, '0');
45 +         FILL (header->header.mode, '0');
46 +  }
47    uid_to_uname (0, &tmpname);
48    UNAME_TO_CHARS (tmpname, header->header.uname);
49    free (tmpname);
50 @@ -724,7 +736,7 @@ write_header_name (struct tar_stat_info *st)
51        return write_short_name (st);
52      }
53    else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
54 -          < strlen (st->file_name))
55 +          < strlen (st->file_name) + debian_longlink_hack)
56      return write_long_name (st);
57    else
58      return write_short_name (st);
59 @@ -1476,7 +1488,7 @@ dump_hard_link (struct tar_stat_info *st)
60           block_ordinal = current_block_ordinal ();
61           assign_string (&st->link_name, link_name);
62           if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
63 -             < strlen (link_name))
64 +             < strlen (link_name) + debian_longlink_hack)
65             write_long_link (st);
66  
67           st->stat.st_size = 0;
68 diff --git a/src/tar.c b/src/tar.c
69 index 4f5017d..b72e25b 100644
70 --- a/src/tar.c
71 +++ b/src/tar.c
72 @@ -1246,6 +1246,26 @@ expand_pax_option (struct tar_args *targs, const char *arg)
73    return res;
74  }
75  
76 +/* Debian specific environment variable used by pristine-tar to enable use of
77 + * longlinks for filenames exactly 100 bytes long. */
78 +void debian_longlink_hack_init (void) {
79 + char *s=getenv ("TAR_LONGLINK_100");
80 + if (s && strcmp(s, "1") == 0)
81 +        debian_longlink_hack=1;
82 + else
83 +        debian_longlink_hack=0;
84 +}
85 +
86 +/* pristine-tar sets this environment variable to force fields in longlinks
87 + * to be zeroed as was the case in tar 1.26. */
88 +void pristine_tar_compat_init (void) {
89 + char *s=getenv ("PRISTINE_TAR_COMPAT");
90 + if (s && strcmp(s, "1") == 0)
91 +        pristine_tar_compat=1;
92 + else
93 +        pristine_tar_compat=0;
94 +}
95 +
96  \f
97  static uintmax_t
98  parse_owner_group (char *arg, uintmax_t field_max, char const **name_option)
99 @@ -2626,6 +2646,9 @@ main (int argc, char **argv)
100    filename_terminator = '\n';
101    set_quoting_style (0, DEFAULT_QUOTING_STYLE);
102  
103 +  debian_longlink_hack_init ();
104 +  pristine_tar_compat_init ();
105 +
106    /* Make sure we have first three descriptors available */
107    stdopen ();
108