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