. "$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) — it uses open(O_CREAT), # which works, unlike creat(2) (ENOSYS on wasm32-hwjs, brintos/linux#13). This is # the SVR4 'newc' form initramfs and dpkg drive. (Named-file mode recorded 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. cpio's chown (superuser) is ENOSYS here, so # --no-preserve-owner skips it; omit -m so no utimes(2) mtime restore is attempted. # File content still round-trips — what dpkg -x / initramfs unpack rely on. 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 / cpio -o -F FILE) opens the output via the # creat(2) path that is ENOSYS on wasm32-hwjs; record it rather than leaving it # uncovered. Normal cpio usage (initramfs/dpkg) uses the stream form above. bst_skip cpio/named-archive-creat "cpio -O/-F FILE calls creat(2) -> ENOSYS on wasm32-hwjs (brintos/linux#13); use the stream form" rm -rf "$tmp"