. "$BST_LIB" require bzip2 bzip2/present tmp=${TMPDIR:-/tmp}/bst-bzip2.$$ line="the quick brown fox jumps over the lazy dog 0123456789" i=0 while [ $i -lt 64 ]; do printf "%s\n" "$line"; i=$((i+1)); done > "$tmp.in" 2>/dev/null # The stream form (bzip2 -c > file) touches no file attributes. It used to be the # only form covered here, because the named-file path bailed "Function not # implemented" on its post-write attribute restoration; that is brintos/linux#8, # now fixed, and the named-file cases at the end of this file cover it. check bzip2/compress sh -c "bzip2 -c '$tmp.in' > '$tmp.bz2'" # bzip2 stream carries the printable "BZh" magic. Read the first 3 bytes with dd # (bs/count), not head -c: busybox head has no -c byte-count option. check_out bzip2/magic "BZh" sh -c "dd if='$tmp.bz2' bs=3 count=1 2>/dev/null" # integrity self-check of the compressed stream check bzip2/test bzip2 -t "$tmp.bz2" # decompress round-trip recovers the original text (bunzip2 alternative, -c) check_out bzip2/roundtrip "$line" sh -c "bunzip2 -c '$tmp.bz2'" # bzcat alternative decompresses too check_out bzip2/bzcat "$line" sh -c "bzcat '$tmp.bz2'" # byte-for-byte identity of the round-trip bunzip2 -c "$tmp.bz2" > "$tmp.out" 2>/dev/null check bzip2/identical cmp -s "$tmp.in" "$tmp.out" rm -f "$tmp.bz2" "$tmp.out" # --- the named-file form — brintos/linux#8's own reported shape ---------------- # bzip2's default mode restores the source's attributes onto the output: # applySavedFileAttrToOutputFile() fchmod()s the output fd and treats a failure as # fatal, then fchown()s it (return ignored), and utime()s after close. All of those # were ENOSYS, so bzip2 wrote a valid archive and then deleted it — the failure the # issue reported. The mode assertion is the load-bearing one: it distinguishes a # real fchmod from one that is accepted and dropped, which a bare rc=0 cannot. named_cases() { _dir=$1; _sfx=$2 _n="$_dir/bst-bzip2-named.$$" rm -f "$_n" "$_n.bz2" 2>/dev/null cp "$tmp.in" "$_n" 2>/dev/null chmod 0640 "$_n" 2>/dev/null check "bzip2/named-compress$_sfx" bzip2 -kf "$_n" check "bzip2/named-output$_sfx" test -s "$_n.bz2" check "bzip2/named-keep$_sfx" test -f "$_n" check_out "bzip2/named-roundtrip$_sfx" "$line" sh -c "bunzip2 -c '$_n.bz2'" if command -v stat >/dev/null 2>&1; then check_eq "bzip2/named-mode$_sfx" "640" "$(stat -c %a "$_n.bz2" 2>/dev/null)" else bst_skip "bzip2/named-mode$_sfx" "stat not installed on this image" fi rm -f "$_n" "$_n.bz2" 2>/dev/null } named_cases "${TMPDIR:-/tmp}" "" # The rootfs is the cloud virtio-fs, which does not behave like the tmpfs and is # where the mode round-trip is worth asserting most. Read-only on an anonymously # booted session — skip rather than fail, as 65-vfs does. vdir=/var/lib/bst-bzip2 if mkdir -p "$vdir" 2>/dev/null; then named_cases "$vdir" "-vfs" rmdir "$vdir" 2>/dev/null else for c in compress output keep roundtrip mode; do bst_skip "bzip2/named-$c-vfs" "rootfs read-only (anonymous session); needs an owner-authenticated boot" done fi rm -f "$tmp.in"