need the actual patch, too, of course...
[debian/tar] / debian / patches / files-from-and-recursive-extract.diff
1 diff --git a/src/common.h b/src/common.h
2 index edf787c..3cc2011 100644
3 --- a/src/common.h
4 +++ b/src/common.h
5 @@ -725,7 +725,7 @@ int uname_to_uid (char const *uname, uid_t *puid);
6  void name_init (void);
7  void name_add_name (const char *name, int matching_flags);
8  void name_add_dir (const char *name);
9 -void name_add_file (const char *name, int term);
10 +void name_add_file (const char *name, int term, int matching_flags);
11  void name_term (void);
12  const char *name_next (int change_dirs);
13  void name_gather (void);
14 diff --git a/src/names.c b/src/names.c
15 index 594e7fd..e3e145a 100644
16 --- a/src/names.c
17 +++ b/src/names.c
18 @@ -258,6 +258,21 @@ name_elt_alloc (void)
19    return elt;
20  }
21  
22 +static struct name_elt *
23 +name_elt_alloc_matflags (int matflags)
24 +{
25 +  static int prev_flags = 0; /* FIXME: Or EXCLUDE_ANCHORED? */
26 +  struct name_elt *ep = name_elt_alloc ();
27 +  if (prev_flags != matflags)
28 +    {
29 +      ep->type = NELT_FMASK;
30 +      ep->v.matching_flags = matflags;
31 +      prev_flags = matflags;
32 +      ep = name_elt_alloc ();
33 +    }
34 +  return ep;
35 +}
36 +
37  static void
38  name_list_adjust (void)
39  {
40 @@ -276,20 +291,13 @@ name_list_advance (void)
41    free (elt);
42  }
43  
44 -/* Add to name_array the file NAME with fnmatch options MATCHING_FLAGS */
45 +
46 +/* Add to name_array the file NAME with fnmatch options MATFLAGS */
47  void
48 -name_add_name (const char *name, int matching_flags)
49 +name_add_name (const char *name, int matflags)
50  {
51 -  static int prev_flags = 0; /* FIXME: Or EXCLUDE_ANCHORED? */
52 -  struct name_elt *ep = name_elt_alloc ();
53 +  struct name_elt *ep = name_elt_alloc_matflags (matflags);
54  
55 -  if (prev_flags != matching_flags)
56 -    {
57 -      ep->type = NELT_FMASK;
58 -      ep->v.matching_flags = matching_flags;
59 -      prev_flags = matching_flags;
60 -      ep = name_elt_alloc ();
61 -    }
62    ep->type = NELT_NAME;
63    ep->v.name = name;
64    name_count++;
65 @@ -305,9 +313,10 @@ name_add_dir (const char *name)
66  }
67  
68  void
69 -name_add_file (const char *name, int term)
70 +name_add_file (const char *name, int term, int matflags)
71  {
72 -  struct name_elt *ep = name_elt_alloc ();
73 +  struct name_elt *ep = name_elt_alloc_matflags (matflags);
74 +
75    ep->type = NELT_FILE;
76    ep->v.file.name = name;
77    ep->v.file.term = term;
78 @@ -389,6 +398,15 @@ add_file_id (const char *filename)
79    file_id_list = p;
80    return 0;
81  }
82 +
83 +/* Chop trailing slashes.  */
84 +static void
85 +chopslash (char *str)
86 +{
87 +  char *p = str + strlen (str) - 1;
88 +  while (p > str && ISSLASH (*p))
89 +    *p-- = '\0';
90 +}
91  \f
92  enum read_file_list_state  /* Result of reading file name from the list file */
93    {
94 @@ -428,7 +446,7 @@ read_name_from_file (struct name_elt *ent)
95    if (counter == name_buffer_length)
96      name_buffer = x2realloc (name_buffer, &name_buffer_length);
97    name_buffer[counter] = 0;
98 -
99 +  chopslash (name_buffer);
100    return (counter == 0 && c == EOF) ? file_list_end : file_list_success;
101  }
102  
103 @@ -518,7 +536,6 @@ copy_name (struct name_elt *ep)
104  {
105    const char *source;
106    size_t source_len;
107 -  char *cursor;
108  
109    source = ep->v.name;
110    source_len = strlen (source);
111 @@ -536,11 +553,7 @@ copy_name (struct name_elt *ep)
112        name_buffer = xmalloc(name_buffer_length + 2);
113      }
114    strcpy (name_buffer, source);
115 -
116 -  /* Zap trailing slashes.  */
117 -  cursor = name_buffer + strlen (name_buffer) - 1;
118 -  while (cursor > name_buffer && ISSLASH (*cursor))
119 -    *cursor-- = '\0';
120 +  chopslash (name_buffer);
121  }
122  
123  \f
124 @@ -553,7 +566,8 @@ static int matching_flags; /* exclude_fnmatch options */
125     the request to change to the given directory.
126  
127     Entries of type NELT_FMASK cause updates of the matching_flags
128 -   value. */
129 +   value.
130 +*/
131  static struct name_elt *
132  name_next_elt (int change_dirs)
133  {
134 diff --git a/src/tar.c b/src/tar.c
135 index cd32379..225c624 100644
136 --- a/src/tar.c
137 +++ b/src/tar.c
138 @@ -1641,7 +1641,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
139        break;
140  
141      case 'T':
142 -      name_add_file (arg, filename_terminator);
143 +      name_add_file (arg, filename_terminator, MAKE_INCL_OPTIONS (args));
144        /* Indicate we've been given -T option. This is for backward
145          compatibility only, so that `tar cfT archive /dev/null will
146          succeed */
147 diff --git a/tests/Makefile.am b/tests/Makefile.am
148 index 6684d1d..c71d294 100644
149 --- a/tests/Makefile.am
150 +++ b/tests/Makefile.am
151 @@ -43,6 +43,8 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
152  
153  TESTSUITE_AT = \
154   T-cd.at\
155 + T-dir00.at\
156 + T-dir01.at\
157   T-empty.at\
158   T-null.at\
159   T-rec.at\
160 diff --git a/tests/T-dir00.at b/tests/T-dir00.at
161 new file mode 100644
162 index 0000000..7f89fcf
163 --- /dev/null
164 +++ b/tests/T-dir00.at
165 @@ -0,0 +1,45 @@
166 +# Process this file with autom4te to create testsuite. -*- Autotest -*-
167 +#
168 +# Test suite for GNU tar.
169 +# Copyright 2014 Free Software Foundation, Inc.
170 +
171 +# This file is part of GNU tar.
172 +
173 +# GNU tar is free software; you can redistribute it and/or modify
174 +# it under the terms of the GNU General Public License as published by
175 +# the Free Software Foundation; either version 3 of the License, or
176 +# (at your option) any later version.
177 +
178 +# GNU tar is distributed in the hope that it will be useful,
179 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
180 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181 +# GNU General Public License for more details.
182 +
183 +# You should have received a copy of the GNU General Public License
184 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
185 +
186 +# Tar 1.27 and 1.28 did not extract files under directory memberes listed
187 +# in the file read by --file-from.
188 +#
189 +# Reported-by: Jean-Louis Martineau <address@hidden>
190 +# References: <address@hidden>,
191 +#             http://lists.gnu.org/archive/html/bug-tar/2014-09/msg00006.html
192 +
193 +AT_SETUP([recursive extraction from --files-from])
194 +AT_KEYWORDS([files-from extract T-dir T-dir00])
195 +AT_TAR_CHECK([
196 +mkdir dir
197 +genfile -f dir/file1
198 +genfile -f dir/file2
199 +tar cf archive dir
200 +rm -rf dir
201 +echo dir > list
202 +tar xfTv archive list
203 +],
204 +[0],
205 +[dir/
206 +dir/file1
207 +dir/file2
208 +])
209 +AT_CLEANUP
210 +
211 diff --git a/tests/T-dir01.at b/tests/T-dir01.at
212 new file mode 100644
213 index 0000000..155a373
214 --- /dev/null
215 +++ b/tests/T-dir01.at
216 @@ -0,0 +1,45 @@
217 +# Process this file with autom4te to create testsuite. -*- Autotest -*-
218 +#
219 +# Test suite for GNU tar.
220 +# Copyright 2014 Free Software Foundation, Inc.
221 +
222 +# This file is part of GNU tar.
223 +
224 +# GNU tar is free software; you can redistribute it and/or modify
225 +# it under the terms of the GNU General Public License as published by
226 +# the Free Software Foundation; either version 3 of the License, or
227 +# (at your option) any later version.
228 +
229 +# GNU tar is distributed in the hope that it will be useful,
230 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
231 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
232 +# GNU General Public License for more details.
233 +
234 +# You should have received a copy of the GNU General Public License
235 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
236 +
237 +# Tar 1.27 and 1.28 did not remove trailing slashes from file names
238 +# obtained with the --file-from option.
239 +#
240 +# Reported-by: Jean-Louis Martineau <address@hidden>
241 +# References: <address@hidden>,
242 +#             http://lists.gnu.org/archive/html/bug-tar/2014-09/msg00006.html
243 +
244 +AT_SETUP([trailing slash in --files-from])
245 +AT_KEYWORDS([files-from extract T-dir T-dir01])
246 +AT_TAR_CHECK([
247 +mkdir dir
248 +genfile -f dir/file1
249 +genfile -f dir/file2
250 +tar cf archive dir
251 +rm -rf dir
252 +echo dir/ > list
253 +tar xfTv archive list
254 +],
255 +[0],
256 +[dir/
257 +dir/file1
258 +dir/file2
259 +])
260 +AT_CLEANUP
261 +
262 diff --git a/tests/testsuite.at b/tests/testsuite.at
263 index 7f8e4c4..f28e86c 100644
264 --- a/tests/testsuite.at
265 +++ b/tests/testsuite.at
266 @@ -205,6 +205,8 @@ m4_include([T-empty.at])
267  m4_include([T-null.at])
268  m4_include([T-zfile.at])
269  m4_include([T-nonl.at])
270 +m4_include([T-dir00.at])
271 +m4_include([T-dir01.at])
272  
273  AT_BANNER([Various options])
274  m4_include([indexfile.at])