682151b70d82f1379b02cdf0c90e470f4c09508d
[debian/tar] / debian / patches / pristine-tar.diff
1 diff --git a/src/common.h b/src/common.h
2 index 42fd539..fe032ec 100644
3 --- a/src/common.h
4 +++ b/src/common.h
5 @@ -906,4 +906,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 4344a24..de10cae 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,11 @@ 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, 0);
43 +  if (pristine_tar_compat) {
44 +         FILL (header->header.mtime, '0');
45 +         FILL (header->header.mode, '0');
46 +  }
47 +
48    uid_to_uname (0, &tmpname);
49    UNAME_TO_CHARS (tmpname, header->header.uname);
50    free (tmpname);
51 @@ -724,7 +737,7 @@ write_header_name (struct tar_stat_info *st)
52        return write_short_name (st);
53      }
54    else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
55 -          < strlen (st->file_name))
56 +          < strlen (st->file_name) + debian_longlink_hack)
57      return write_long_name (st);
58    else
59      return write_short_name (st);
60 @@ -1476,7 +1489,7 @@ dump_hard_link (struct tar_stat_info *st)
61           block_ordinal = current_block_ordinal ();
62           assign_string (&st->link_name, link_name);
63           if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
64 -             < strlen (link_name))
65 +             < strlen (link_name) + debian_longlink_hack)
66             write_long_link (st);
67  
68           st->stat.st_size = 0;
69 diff --git a/src/tar.c b/src/tar.c
70 index 4f5017d..b72e25b 100644
71 --- a/src/tar.c
72 +++ b/src/tar.c
73 @@ -1246,6 +1246,26 @@ expand_pax_option (struct tar_args *targs, const char *arg)
74    return res;
75  }
76  
77 +/* Debian specific environment variable used by pristine-tar to enable use of
78 + * longlinks for filenames exactly 100 bytes long. */
79 +void debian_longlink_hack_init (void) {
80 + char *s=getenv ("TAR_LONGLINK_100");
81 + if (s && strcmp(s, "1") == 0)
82 +        debian_longlink_hack=1;
83 + else
84 +        debian_longlink_hack=0;
85 +}
86 +
87 +/* pristine-tar sets this environment variable to force fields in longlinks
88 + * to be zeroed as was the case in tar 1.26. */
89 +void pristine_tar_compat_init (void) {
90 + char *s=getenv ("PRISTINE_TAR_COMPAT");
91 + if (s && strcmp(s, "1") == 0)
92 +        pristine_tar_compat=1;
93 + else
94 +        pristine_tar_compat=0;
95 +}
96 +
97  \f
98  static uintmax_t
99  parse_owner_group (char *arg, uintmax_t field_max, char const **name_option)
100 @@ -2626,6 +2646,9 @@ main (int argc, char **argv)
101    filename_terminator = '\n';
102    set_quoting_style (0, DEFAULT_QUOTING_STYLE);
103  
104 +  debian_longlink_hack_init ();
105 +  pristine_tar_compat_init ();
106 +
107    /* Make sure we have first three descriptors available */
108    stdopen ();
109