From 28bb51310ca3da7a138256f2579f6bd9fedcff50 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Thu, 12 Nov 2026 00:52:35 +0000 Subject: [PATCH] install-phone: say so when the work directory can't be created or written Since #648 the shipped ramdisk is read in a directory of its own in --work before the phone is contacted, so --verify-only now creates the work directory. On a home that can't be written (or with a --work the user can't write) it stopped at mkdir's or mktemp's own error, which with uutils coreutils doesn't even name the path. It now stops with the installer's message, naming the work directory and --work DIR. A full install stops there too, before the phone; the later mkdir and chmod of --work only run after this one has succeeded, so they are left alone. Tested: tests/install-phone-initramfs gains the case (a --work under a directory the user can't write, a --work that exists but can't be written, both with --verify-only, and a full install), which fails with main's tool ("says why it refuses a --work that can't be created"); both install-phone suites pass, the initramfs one under umask 077, 022 and 002; tools/pr-check origin/main; tests/all. A bundle's ./install --unsigned --verify-only in a sandbox with a read-only home now ends with the message. Not tested: on a phone (laptop-side only), or as root (the test skips its case there; root can write a mode 555 directory). Co-Authored-By: Claude Opus 5.5 --- tests/install-phone-initramfs | 17 +++++++++++++++-- tools/install-phone | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/install-phone-initramfs b/tests/install-phone-initramfs index 769dc3ce2..1178d00af 100755 --- a/tests/install-phone-initramfs +++ b/tests/install-phone-initramfs @@ -153,8 +153,8 @@ refused() { # why message [args]: install refused, said why, flashed nothing grep -cF -- "$2" "$t/out" >/dev/null || { cat "$t/out"; fail "says why it refuses $1"; } [[ -z $(ls -A "$t/flashed") ]] || fail "nothing is flashed when it refuses $1" } -verify_refused() { # why message: --verify-only refuses it too, and contacts no phone - refused "$1 with --verify-only" "$2" --verify-only +verify_refused() { # why message [args]: --verify-only refuses it too, and contacts no phone + refused "$1 with --verify-only" "$2" --verify-only "${@:3}" [[ ! -s $t/fastboot.log ]] || fail "--verify-only contacts no phone when it refuses $1" } # slot_b root images: the stand-in phone's slot B partitions hold those @@ -224,6 +224,19 @@ still_staged "an install refused for another phone's --serial" rm -r "$t/work" pass "--verify-only, and an install refused before the answers, leave another install's staged files in --work alone" +# A work directory that can't be created or written (as under a read-only +# home) stops with the installer's message, before the phone +if ((EUID != 0)); then + mkdir -p "$t/locked" && chmod 555 "$t/locked" + why="can't create or write to the work directory" + verify_refused "a --work that can't be created" "$why $t/locked/work (give one you can write to with --work DIR)" --work "$t/locked/work" + verify_refused "a --work that can't be written" "$why $t/locked (give one you can write to with --work DIR)" --work "$t/locked" + refused "a full install with a --work that can't be written" "$why $t/locked " --work "$t/locked" + [[ ! -s $t/fastboot.log ]] || fail "a full install with a --work that can't be written contacts no phone" + chmod 755 "$t/locked" + pass "a --work that can't be created or written stops with the installer's message, before the phone" +fi + # The hook's first run after the install: slot B already holds its images. # Slot B as the bundle's images left it (before this change) still needed # the rewrite #564 found. diff --git a/tools/install-phone b/tools/install-phone index 6b5a906e8..99f76032f 100755 --- a/tools/install-phone +++ b/tools/install-phone @@ -465,8 +465,8 @@ if [[ " $BOOT_IMAGES " == *" vendor_kernel_boot "* ]]; then ramdisk_image=vendor elif [[ " $BOOT_IMAGES " == *" vendor_boot "* ]]; then ramdisk_image=vendor_boot; fi if [[ -n $ramdisk_image ]]; then [[ -z ${avb_size[$ramdisk_image]:-} ]] || die "$conf: AVB_FOOTERS names $ramdisk_image, which carries the ramdisk: the owner's key can't be added to a signed image" - mkdir -p "$work" - verify_dir=$(mktemp -d "$work/verify.XXXXXX") + mkdir -p "$work" && verify_dir=$(mktemp -d "$work/verify.XXXXXX") || + die "can't create or write to the work directory $work (give one you can write to with --work DIR)" trap 'rm -rf "$verify_dir"' EXIT vendor_ramdisk get "$images/$ramdisk_image.img" "$verify_dir/shipped.cpio.lz4" || die "can't read the ramdisk of $ramdisk_image.img" lz4 -dc "$verify_dir/shipped.cpio.lz4" > "$verify_dir/shipped.cpio" || die "lz4 couldn't decompress $ramdisk_image.img's ramdisk"