Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package tar | 5 package tar |
6 | 6 |
7 // TODO(dsymonds): | 7 // TODO(dsymonds): |
8 // - catch more errors (no first header, etc.) | 8 // - catch more errors (no first header, etc.) |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 192 |
193 _, tw.err = tw.w.Write(header) | 193 _, tw.err = tw.w.Write(header) |
194 | 194 |
195 return tw.err | 195 return tw.err |
196 } | 196 } |
197 | 197 |
198 // writeUSTARLongName splits a USTAR long name hdr.Name. | 198 // writeUSTARLongName splits a USTAR long name hdr.Name. |
199 // name must be < 256 characters. errNameTooLong is returned | 199 // name must be < 256 characters. errNameTooLong is returned |
200 // if hdr.Name can't be split. The splitting heuristic | 200 // if hdr.Name can't be split. The splitting heuristic |
201 // is compatible with gnu tar. | 201 // is compatible with gnu tar. |
202 func (tw *Writer) splitUSTARLongName(name string) (prefix, suffix string, err er ror) { | 202 func (tw *Writer) splitUSTARLongName(name string) (prefix, suffix string, err er ror) { |
chressie1
2013/02/07 08:03:39
it looks like the method is splitting also the fil
shanemhansen
2013/02/07 19:50:27
It is, it assumes only long filenames are being pa
| |
203 length := len(name) | 203 length := len(name) |
204 if length > fileNamePrefixSize+1 { | 204 if length > fileNamePrefixSize+1 { |
205 length = fileNamePrefixSize + 1 | 205 length = fileNamePrefixSize + 1 |
206 } else if name[length-1] == '/' { | 206 } else if name[length-1] == '/' { |
207 length-- | 207 length-- |
chressie1
2013/02/07 08:03:39
shouldn't this be length++ ? (explanation below)
| |
208 } | 208 } |
209 » i := strings.LastIndex(name, "/") | 209 » i := strings.LastIndex(name[:length], "/") |
210 nlen := length - i - 1 | 210 nlen := length - i - 1 |
chressie1
2013/02/07 08:03:39
if name ends with a slash and the length of name i
shanemhansen
2013/02/07 19:50:27
You have an excellent point. I transliterated this
chressie1
2013/02/08 07:32:10
they use length to init the for loop, so if name e
shanemhansen
2013/02/08 07:35:34
Done.
| |
211 » if i == 0 || nlen > fileNameSize || nlen == 0 { | 211 » if i <= 0 || nlen > fileNameSize || nlen == 0 { |
chressie1
2013/02/08 07:32:10
in addition, i think you need to check for i <= 0,
shanemhansen
2013/02/08 07:35:34
Done.
| |
212 err = errNameTooLong | 212 err = errNameTooLong |
213 return | 213 return |
214 } | 214 } |
215 prefix, suffix = name[:i], name[i+1:] | 215 prefix, suffix = name[:i], name[i+1:] |
216 return | 216 return |
217 } | 217 } |
218 | 218 |
219 // writePaxHeader writes an extended pax header to the | 219 // writePaxHeader writes an extended pax header to the |
220 // archive. | 220 // archive. |
221 func (tw *Writer) writePAXHeader(hdr *Header) error { | 221 func (tw *Writer) writePAXHeader(hdr *Header) error { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 | 304 |
305 // trailer: two zero blocks | 305 // trailer: two zero blocks |
306 for i := 0; i < 2; i++ { | 306 for i := 0; i < 2; i++ { |
307 _, tw.err = tw.w.Write(zeroBlock) | 307 _, tw.err = tw.w.Write(zeroBlock) |
308 if tw.err != nil { | 308 if tw.err != nil { |
309 break | 309 break |
310 } | 310 } |
311 } | 311 } |
312 return tw.err | 312 return tw.err |
313 } | 313 } |
LEFT | RIGHT |