diff options
author | Rob Landley <rob@landley.net> | 2019-09-18 13:45:35 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-09-18 13:45:35 -0500 |
commit | 66aebaaeeefde97a33d8b35ea2d20dd3c1eebb47 (patch) | |
tree | 82fb4e99b1b4465e86bfc552c0689c60f46fc0ee /toys/posix | |
parent | 0dedd13253f4e3fc4ddaf912f503b30261d2ee63 (diff) | |
download | toybox-66aebaaeeefde97a33d8b35ea2d20dd3c1eebb47.tar.gz |
Fix tar creation with hole at end.
The "gratuitous extra entry" is only gratuitous when there isn't a hole. (Which
we can detect and not include but then we wouldn't match other implementations.)
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/tar.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c index d3680ad2..e513424e 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -313,20 +313,13 @@ static int add_to_tar(struct dirtree *node) TT.sparse[TT.sparselen++] = ld; len += TT.sparse[TT.sparselen++] = lo-ld; } - 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 (lo == st->st_size || (ld = lseek(fd, lo, SEEK_DATA)) < lo) break; } // If there were extents, change type to S record - if (TT.sparselen) { + if (TT.sparselen>2) { + TT.sparse[TT.sparselen++] = st->st_size; + TT.sparse[TT.sparselen++] = 0; hdr.type = 'S'; lnk = (char *)&hdr; for (i = 0; i<TT.sparselen && i<8; i++) @@ -337,7 +330,7 @@ static int add_to_tar(struct dirtree *node) if (TT.sparselen>8) lnk[482] = 1; itoo(lnk+483, 12, st->st_size); ITOO(hdr.size, len); - } + } else TT.sparselen = 0; lseek(fd, 0, SEEK_SET); } } |