. "$BST_LIB" require cpio cpio/present # The shipped /bin/cpio must be GNU cpio: ALTERNATIVE_PRIORITY 100 outranks both # other claimants, bsdcpio (80) and the busybox applet (50). check_out cpio/gnu-version "GNU cpio" cpio --version tmp=${TMPDIR:-/tmp}/bst-cpio.$$ 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" # Copy-out to STDOUT, not a named file: cpio's create mode is stream-oriented by # design (cpio -o > file, the shell opens the output). This is the SVR4 'newc' # form initramfs and dpkg drive. (Named-file mode is below.) check cpio/copy-out sh -c "cd '$tmp/src' && find . | cpio -o -H newc > '$tmp/arc.cpio'" # newc archives begin with the ASCII magic 070701. check_out cpio/newc-magic "070701" sh -c "head -c 6 '$tmp/arc.cpio'" # list enumerates members from the stream; the nested path proves recursion. check_out cpio/list "sub/b.txt" sh -c "cpio -itv < '$tmp/arc.cpio'" # Copy-in extract from the stream. The owner restore is skipped # (--no-preserve-owner) and -m omitted so no mtime restore is attempted; file # content still round-trips — what dpkg -x / initramfs unpack rely on. # BRINTOS-WORKAROUND: linux#5 revisit — added because chown/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 flag. mkdir -p "$tmp/out" check cpio/copy-in sh -c "cd '$tmp/out' && cpio -id --no-preserve-owner < '$tmp/arc.cpio'" check cpio/identical cmp -s "$tmp/src/a.txt" "$tmp/out/a.txt" # Copy-pass clones a directory tree file-to-file (no archive), the third stream # form; same --no-preserve-owner / no-mtime treatment. mkdir -p "$tmp/clone" check cpio/copy-pass sh -c "cd '$tmp/src' && find . | cpio -pd --no-preserve-owner '$tmp/clone'" check cpio/clone-ident cmp -s "$tmp/src/sub/b.txt" "$tmp/clone/sub/b.txt" # Named-file create (cpio -O FILE) — the form that reaches creat(2), where the # stream form above does not. Read the archive back rather than trusting rc=0. check cpio/named-create sh -c "cd '$tmp/src' && find . | cpio -o -H newc -O '$tmp/named.cpio'" check_out cpio/named-magic "070701" sh -c "head -c 6 '$tmp/named.cpio'" check_out cpio/named-list "sub/b.txt" sh -c "cpio -itv < '$tmp/named.cpio'" rm -rf "$tmp"