(you beat me getting back to this...)

On Sun, Sep 15, 2019 at 12:18 AM Rob Landley <[email protected]> wrote:
>
> On 9/13/19 8:17 PM, Rob Landley wrote:
> > I think what we need to do is add up the segments. (Which is what I thought 
> > it
> > _was_ doing, but my head cold has turned into dizzy+headache and I has a 
> > tired.)
> >
> > I can fix this when I feel better if you don't get to it.
>
> I pushed a patch. It only calls truncate() when it hits a zero length segment
> (and only when lseek() didn't fail, so writing to a nonseekable output 
> shouldn't
> gratuitously fail at the truncate)

(yeah, i hadn't thought about anything other than regular files.)

>, and it uses the last offset+length as a
> sparse file as the display length.
>
> I think that fixes it?

it fixes extraction, yes. i can confirm that i get the same results
for the motivating tar files with GNU and toybox tar now.

but if you try the attached patch which adds a test for a sparse file
with a hole at the end, it passes with TEST_HOST=1 but fails otherwise
because i don't think we're adding the final entry?

> Rob
From a34fd5143a991643386db0b3b426b8cec1b88fa6 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Sun, 15 Sep 2019 11:00:20 -0700
Subject: [PATCH] tar.test: add a test for a sparse file with a hole at the
 end.

---
 tests/tar.test | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tests/tar.test b/tests/tar.test
index afa35e94..b16d5591 100644
--- a/tests/tar.test
+++ b/tests/tar.test
@@ -222,17 +222,27 @@ rm fweep
 for i in $(seq 8 3 200)
 do
   dd if=/dev/zero of=fweep bs=65536 seek=$i count=1 2>/dev/null
+  dd if=/dev/zero of=fweep2 bs=65536 seek=$i count=1 2>/dev/null
 done
+truncate -s 20m fweep2
 
 testing "sparse double overflow" "$TAR --sparse fweep | SUM 7" \
   "f1fe57f8313a9d682ec9013a80f3798910b6ff51\n" "" ""
 
 tar c --sparse fweep > fweep.tar
-FWEEP=$(du fweep)
+FWEEP=$(stat -c "%b %s" fweep)
 rm fweep
-testing "sparse extract" "tar xf fweep.tar && du fweep" "$FWEEP\n" "" ""
+testing "sparse extract" "tar xf fweep.tar && stat -c '%b %s' fweep" \
+  "$FWEEP\n" "" ""
 rm fweep fweep.tar
 
+tar c --sparse fweep2 > fweep2.tar
+FWEEP=$(stat -c "%b %s" fweep2)
+rm fweep2
+testing "sparse extract hole at end" \
+  "strace -e ftruncate tar xf fweep2.tar && stat -c '%b %s' fweep2" "$FWEEP\n" "" ""
+rm fweep2 fweep2.tar
+
 if false
 then
 
-- 
2.23.0.237.gc6a4ce50a0-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to