[Toybox] What does the xxd-pipe stuff in tests.tar do?

enh enh at google.com
Tue Aug 17 09:57:53 PDT 2021


wow, i was convinced i didn't write that and it must have been something
you did, but `git blame` disagrees.

hmm... it looks like what happened was that i was trying to preserve the
old use of hd(1)? see the minus lines at the top of this diff:

-export BLOCKS=3
-SUM='head -c $(($BLOCKS*512)) | sha1sum | sed "s/ .*//"'
-[ -n "$TARHD" ] && SUM="tee >(hd >&2) | $SUM"
+
+# Also amount of trailing NUL padding varies (1024 bytes is minimum,
+# gnu/dammit does more) so look at first N 512-byte frames when
+# analyzing header content.
+function SUM()
+{
+  if [ -n "$TARHD" ]; then
+    # (Android's shell doesn't support process substitution.)
+    mkfifo xxd-pipe
+    xxd <xxd-pipe & pid=$!
+    tee xxd-pipe | head -c $(($1*512)) | sha1sum | sed "s/ .*//"
+    rm xxd-pipe
+    wait $pid
+  else
+    head -c $(($1*512)) | sha1sum | sed "s/ .*//"
+  fi
+}

but, yeah, afaict this is just an overly-literal translation of the old
test into something that still works on Android. i think a temporary file
in a snapshot would be fine. (in fact preferable, because my checkin
comment complains that i wish i'd known about TARHD while trying to debug
the tar tests. with a temporary file and stop on error, i wouldn't have
needed to learn anything.)

On Mon, Aug 16, 2021 at 11:37 PM Rob Landley <rob at landley.net> wrote:

> I hit a transient tar bug (https://landley.net/notes-2021.html#06-08-2021)
> I
> couldn't reproduce so I'm trying to redo the SUM plumbing in tar to save a
> snapshot of the raw data and it seems like the OBVIOUS thing to do would
> be:
>
> function SUM()
> {
>   tee save.dat | head -c $(($1*512)) | sha1sum | sed "s/ .*//"
> }
>
> But right NOW it looks like:
>
> function SUM()
> {
>   if [ -n "$TARHD" ]; then
>     # (Android's shell doesn't support process substitution.)
>     mkfifo xxd-pipe
>     xxd <xxd-pipe & pid=$!
>     tee xxd-pipe | head -c $(($1*512)) | sha1sum | sed "s/ .*//"
>     rm xxd-pipe
>     wait $pid
>   else
>     head -c $(($1*512)) | sha1sum | sed "s/ .*//"
>   fi
> }
>
> And... is this actually used, or can it go if I save a snapshot of the
> data for
> later analysis in the "stop when you hit an error" mode which is now the
> default?
>
> Rob
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20210817/5a19ee6a/attachment.htm>


More information about the Toybox mailing list