patch from Joey Hess for pristine-tar backwards compatibility
[debian/tar] / debian / patches / pristine_tar_compat
1 From e36454201ec81374bf4d2d09877e6c345a6fddab Mon Sep 17 00:00:00 2001
2 From: Joey Hess <joeyh@debian.org>
3 Date: Sun, 27 Oct 2013 13:16:52 -0400
4 Subject: [PATCH] add PRISTINE_TAR_COMPAT
5
6 ---
7  debian/patches/longlink-hack.diff |  72 -------------------------
8  debian/patches/pristine-tar.diff  | 108 ++++++++++++++++++++++++++++++++++++++
9  debian/patches/series             |   2 +-
10  3 files changed, 109 insertions(+), 73 deletions(-)
11  delete mode 100644 debian/patches/longlink-hack.diff
12  create mode 100644 debian/patches/pristine-tar.diff
13
14 diff --git a/debian/patches/longlink-hack.diff b/debian/patches/longlink-hack.diff
15 deleted file mode 100644
16 index b6bc385..0000000
17 --- a/debian/patches/longlink-hack.diff
18 +++ /dev/null
19 @@ -1,72 +0,0 @@
20 -diff --git a/src/common.h b/src/common.h
21 -index eb801bb..4aaace5 100644
22 ---- a/src/common.h
23 -+++ b/src/common.h
24 -@@ -907,4 +907,6 @@ void finish_deferred_unlinks (void);
25 - /* Module exit.c */
26 - extern void (*fatal_exit_hook) (void);
27
28 -+GLOBAL int debian_longlink_hack;
29 -+
30 - _GL_INLINE_HEADER_END
31 -diff --git a/src/create.c b/src/create.c
32 -index e14e13d..3a84c79 100644
33 ---- a/src/create.c
34 -+++ b/src/create.c
35 -@@ -27,6 +27,8 @@
36 - #include "common.h"
37 - #include <hash.h>
38
39 -+extern int debian_longlink_hack;
40 -+
41 - /* Error number to use when an impostor is discovered.
42 -    Pretend the impostor isn't there.  */
43 - enum { IMPOSTOR_ERRNO = ENOENT };
44 -@@ -724,7 +726,7 @@ write_header_name (struct tar_stat_info *st)
45 -       return write_short_name (st);
46 -     }
47 -   else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
48 --         < strlen (st->file_name))
49 -+         < strlen (st->file_name) + debian_longlink_hack)
50 -     return write_long_name (st);
51 -   else
52 -     return write_short_name (st);
53 -@@ -1476,7 +1478,7 @@ dump_hard_link (struct tar_stat_info *st)
54 -         block_ordinal = current_block_ordinal ();
55 -         assign_string (&st->link_name, link_name);
56 -         if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
57 --            < strlen (link_name))
58 -+            < strlen (link_name) + debian_longlink_hack)
59 -           write_long_link (st);
60
61 -         st->stat.st_size = 0;
62 -diff --git a/src/tar.c b/src/tar.c
63 -index 4f5017d..e9a5126 100644
64 ---- a/src/tar.c
65 -+++ b/src/tar.c
66 -@@ -1246,6 +1246,16 @@ expand_pax_option (struct tar_args *targs, const char *arg)
67 -   return res;
68 - }
69
70 -+/* Debian specific environment variable used by pristine-tar to enable use of
71 -+ * longlinks for filenames exactly 100 bytes long. */
72 -+void debian_longlink_hack_init () {
73 -+ char *s=getenv ("TAR_LONGLINK_100");
74 -+ if (s && strcmp(s, "1") == 0)
75 -+       debian_longlink_hack=1;
76 -+ else
77 -+       debian_longlink_hack=0;
78 -+}
79 -+
80\f
81 - static uintmax_t
82 - parse_owner_group (char *arg, uintmax_t field_max, char const **name_option)
83 -@@ -2626,6 +2636,8 @@ main (int argc, char **argv)
84 -   filename_terminator = '\n';
85 -   set_quoting_style (0, DEFAULT_QUOTING_STYLE);
86
87 -+  debian_longlink_hack_init ();
88 -+
89 -   /* Make sure we have first three descriptors available */
90 -   stdopen ();
91
92 diff --git a/debian/patches/pristine-tar.diff b/debian/patches/pristine-tar.diff
93 new file mode 100644
94 index 0000000..f350acc
95 --- /dev/null
96 +++ b/debian/patches/pristine-tar.diff
97 @@ -0,0 +1,108 @@
98 +diff --git a/src/common.h b/src/common.h
99 +index eb801bb..30f8cf5 100644
100 +--- a/src/common.h
101 ++++ b/src/common.h
102 +@@ -907,4 +907,7 @@ void finish_deferred_unlinks (void);
103 + /* Module exit.c */
104 + extern void (*fatal_exit_hook) (void);
105
106 ++GLOBAL int debian_longlink_hack;
107 ++GLOBAL int pristine_tar_compat;
108 ++
109 + _GL_INLINE_HEADER_END
110 +diff --git a/src/create.c b/src/create.c
111 +index e14e13d..d6e8ea7 100644
112 +--- a/src/create.c
113 ++++ b/src/create.c
114 +@@ -27,6 +27,9 @@
115 + #include "common.h"
116 + #include <hash.h>
117
118 ++extern int debian_longlink_hack;
119 ++extern int pristine_tar_compat;
120 ++
121 + /* Error number to use when an impostor is discovered.
122 +    Pretend the impostor isn't there.  */
123 + enum { IMPOSTOR_ERRNO = ENOENT };
124 +@@ -534,6 +537,11 @@ write_short_name (struct tar_stat_info *st)
125 +   return header;
126 + }
127
128 ++#define FILL(field,byte) do {            \
129 ++  memset(field, byte, sizeof(field)-1);  \
130 ++  (field)[sizeof(field)-1] = 0;          \
131 ++} while (0)
132 ++
133 + /* Write a GNUTYPE_LONGLINK or GNUTYPE_LONGNAME block.  */
134 + static void
135 + write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
136 +@@ -544,6 +552,10 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
137 +   char *tmpname;
138
139 +   header = start_private_header ("././@LongLink", size, start_time.tv_sec);
140 ++  if (pristine_tar_compat) {
141 ++        FILL (header->header.mtime, '0');
142 ++        FILL (header->header.mode, '0');
143 ++  }
144 +   uid_to_uname (0, &tmpname);
145 +   UNAME_TO_CHARS (tmpname, header->header.uname);
146 +   free (tmpname);
147 +@@ -724,7 +736,7 @@ write_header_name (struct tar_stat_info *st)
148 +       return write_short_name (st);
149 +     }
150 +   else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
151 +-         < strlen (st->file_name))
152 ++         < strlen (st->file_name) + debian_longlink_hack)
153 +     return write_long_name (st);
154 +   else
155 +     return write_short_name (st);
156 +@@ -1476,7 +1488,7 @@ dump_hard_link (struct tar_stat_info *st)
157 +         block_ordinal = current_block_ordinal ();
158 +         assign_string (&st->link_name, link_name);
159 +         if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
160 +-            < strlen (link_name))
161 ++            < strlen (link_name) + debian_longlink_hack)
162 +           write_long_link (st);
163
164 +         st->stat.st_size = 0;
165 +diff --git a/src/tar.c b/src/tar.c
166 +index 4f5017d..b72e25b 100644
167 +--- a/src/tar.c
168 ++++ b/src/tar.c
169 +@@ -1246,6 +1246,26 @@ expand_pax_option (struct tar_args *targs, const char *arg)
170 +   return res;
171 + }
172
173 ++/* Debian specific environment variable used by pristine-tar to enable use of
174 ++ * longlinks for filenames exactly 100 bytes long. */
175 ++void debian_longlink_hack_init (void) {
176 ++ char *s=getenv ("TAR_LONGLINK_100");
177 ++ if (s && strcmp(s, "1") == 0)
178 ++       debian_longlink_hack=1;
179 ++ else
180 ++       debian_longlink_hack=0;
181 ++}
182 ++
183 ++/* pristine-tar sets this environment variable to force fields in longlinks
184 ++ * to be zeroed as was the case in tar 1.26. */
185 ++void pristine_tar_compat_init (void) {
186 ++ char *s=getenv ("PRISTINE_TAR_COMPAT");
187 ++ if (s && strcmp(s, "1") == 0)
188 ++       pristine_tar_compat=1;
189 ++ else
190 ++       pristine_tar_compat=0;
191 ++}
192 ++
193\f
194 + static uintmax_t
195 + parse_owner_group (char *arg, uintmax_t field_max, char const **name_option)
196 +@@ -2626,6 +2646,9 @@ main (int argc, char **argv)
197 +   filename_terminator = '\n';
198 +   set_quoting_style (0, DEFAULT_QUOTING_STYLE);
199
200 ++  debian_longlink_hack_init ();
201 ++  pristine_tar_compat_init ();
202 ++
203 +   /* Make sure we have first three descriptors available */
204 +   stdopen ();
205
206 diff --git a/debian/patches/series b/debian/patches/series
207 index 1dfef41..5974cbb 100644
208 --- a/debian/patches/series
209 +++ b/debian/patches/series
210 @@ -1,2 +1,2 @@
211 -longlink-hack.diff
212 +pristine-tar.diff
213  listed03-linux-only
214 -- 
215 1.8.4.rc0
216