From 66aebaaeeefde97a33d8b35ea2d20dd3c1eebb47 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 18 Sep 2019 13:45:35 -0500 Subject: 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.) --- toys/posix/tar.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'toys/posix/tar.c') 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; i8) lnk[482] = 1; itoo(lnk+483, 12, st->st_size); ITOO(hdr.size, len); - } + } else TT.sparselen = 0; lseek(fd, 0, SEEK_SET); } } -- cgit v1.2.3