aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-05-19 01:23:42 -0500
committerRob Landley <rob@landley.net>2019-05-19 01:23:42 -0500
commite35bd58a461d1d5ec38821dab702624f5f24608c (patch)
tree444ec77bc6f8589fc960b9257e8607547a1e8921
parentcfa0256519bd4ef694a7426882160902bab7dece (diff)
downloadtoybox-e35bd58a461d1d5ec38821dab702624f5f24608c.tar.gz
Add pointless trailing --sparse entry for exact binary compartibility.
There's no possible use for this, but debian's tar produces it, so...
-rw-r--r--toys/posix/tar.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c
index 49b1aa1f..1cece411 100644
--- a/toys/posix/tar.c
+++ b/toys/posix/tar.c
@@ -311,15 +311,23 @@ static int add_to_tar(struct dirtree *node)
// Enumerate the extents
while ((lo = lseek(fd, ld, SEEK_HOLE)) != -1) {
if (!(TT.sparselen&511))
- TT.sparse = xrealloc(TT.sparse, (TT.sparselen+512)*sizeof(long long));
+ TT.sparse = xrealloc(TT.sparse, (TT.sparselen+514)*sizeof(long long));
TT.sparse[TT.sparselen++] = ld;
len += TT.sparse[TT.sparselen++] = lo-ld;
- if (lo == st->st_size) break;
+ if (lo == st->st_size) {
+ if (TT.sparselen == 2) TT.sparselen = 0;
+ else {
+ // Gratuitous extra entry for compatibility with other versions
+ TT.sparse[TT.sparselen++] = lo;
+ TT.sparse[TT.sparselen++] = 0;
+ }
+ break;
+ }
if ((ld = lseek(fd, lo, SEEK_DATA)) < lo) ld = st->st_size;
}
// If there were extents, change type to S record
- if (TT.sparselen>2) {
+ if (TT.sparselen) {
hdr.type = 'S';
lnk = (char *)&hdr;
for (i = 0; i<TT.sparselen && i<8; i++)