. "$BST_LIB" require tar tar/present # The shipped /usr/bin/tar must be GNU tar (update-alternatives winner over the # busybox applet); busybox tar lacks the long-option surface dpkg-deb --build needs. check_out tar/gnu-version "GNU tar" tar --version tmp=${TMPDIR:-/tmp}/bst-tar.$$ mkdir -p "$tmp/src/sub" line="the quick brown fox jumps over the lazy dog 0123456789" i=0 while [ $i -lt 32 ]; do printf "%s\n" "$line"; i=$((i+1)); done > "$tmp/src/a.txt" printf "nested payload\n" > "$tmp/src/sub/b.txt" # Archive to STDOUT, not a named file: the shell opens the output and tar writes # stdout. This is how dpkg-deb --build drives tar. (Named-file mode is below.) check tar/create sh -c "cd '$tmp' && tar -cf - src > '$tmp/arc.tar'" # the long-option / --format surface busybox tar rejects but dpkg-deb --build needs. check tar/dpkg-opts sh -c "cd '$tmp' && tar --format=gnu --owner=0 --group=0 -cf - src > '$tmp/dpkg.tar'" # list enumerates members from the stream; the nested path proves recursion. check_out tar/list "src/sub/b.txt" sh -c "tar -tf - < '$tmp/arc.tar'" # extract from the stream. The owner/perms/mtime restore is skipped # (--no-same-owner --no-same-permissions -m); file content still round-trips, # which is what dpkg-deb -x relies on. # BRINTOS-WORKAROUND: linux#5 revisit — these three flags were added because # chown/fchmod/utimes were ENOSYS; the syscalls are wired now, but chown is a # documented accept-and-succeed no-op for uid/gid on virtio-fs, so asserting a # restored owner needs judgement rather than just dropping the flags. mkdir -p "$tmp/out" check tar/extract sh -c "cd '$tmp/out' && tar --no-same-owner --no-same-permissions -m -xf - < '$tmp/arc.tar'" check tar/identical cmp -s "$tmp/src/a.txt" "$tmp/out/src/a.txt" # gzip round-trip via the pipe form dpkg builds data.tar.gz with (busybox gzip). check tar/gzip-create sh -c "cd '$tmp' && tar -cf - src | gzip -c > '$tmp/arc.tgz'" check_out tar/gzip-list "src/a.txt" sh -c "gunzip -c '$tmp/arc.tgz' | tar -tf -" # Named-file archive mode (tar -cf FILE) — the common create form, and the only # one that reaches creat(2). Round-trip it rather than just checking tar's exit # status: a create that silently produced an unreadable archive would still be 0. check tar/named-create sh -c "cd '$tmp' && tar -cf '$tmp/named.tar' src" check_out tar/named-list "src/sub/b.txt" tar -tf "$tmp/named.tar" mkdir -p "$tmp/nout" check tar/named-extract sh -c "cd '$tmp/nout' && tar --no-same-owner --no-same-permissions -m -xf '$tmp/named.tar'" check tar/named-ident cmp -s "$tmp/src/a.txt" "$tmp/nout/src/a.txt" rm -rf "$tmp"