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