Project

General

Profile

Bug #23136 » MountTest.sh

slimmer reproduction with only an arv-mount tmpdir and a static file bound into it - Brett Smith, 09/05/2025 01:29 PM

 
#!/bin/sh

set -e
set -u

fail() {
echo "ERROR: ${2:-failed}" >&2
exit "${1:-9}"
}

cd "$(mktemp --directory --tmpdir="$XDG_RUNTIME_DIR" MountTest-XXXXXXXX)"
mkdir mnt
echo "cat test.sh | tee /mnt/cat.log" >test.sh

UNIT_PATH="$XDG_RUNTIME_DIR/systemd/transient/$(basename "$PWD").service"
MOUNT_SVC="$(basename "$UNIT_PATH")"
cleanup() {
systemctl --user stop "$MOUNT_SVC" || true
rm -f "$UNIT_PATH"
}
trap cleanup EXIT INT TERM QUIT
mkdir -p "$(dirname "$UNIT_PATH")"
cat >"$UNIT_PATH" <<EOF
[Service]
Type=simple
WorkingDirectory=$PWD
ExecStartPre=/usr/bin/rm -rf cache tmp
ExecStartPre=/usr/bin/install -d -m 700 cache tmp
Environment=XDG_CACHE_HOME=$PWD/cache
ExecStart=$(command -v arv-mount) --debug --foreground --read-write --allow-other --ram-cache --mount-tmp tmp0 --disable-event-listening mnt
ExecStop=/usr/bin/fusermount -u mnt
StandardOutput=append:$PWD/arv-mount.out.log
StandardError=append:$PWD/arv-mount.err.log
EOF
systemctl --user daemon-reload

RUN=0
while [ "$RUN" -lt 100 ]; do
RUN=$(( $RUN + 1 ))
printf "\rRun #$RUN at $(date --rfc-3339=seconds)... " >&2
systemctl --user start "$MOUNT_SVC"
while ! [ -d mnt/tmp0 ]; do sleep .25s; done
docker run --interactive --rm \
--workdir /mnt \
--mount type=bind,src="$PWD/mnt/tmp0",dst=/mnt \
--mount type=bind,src="$PWD/test.sh",dst=/mnt/test.sh \
debian:bookworm-slim \
bash -euxo pipefail test.sh >container.out.log 2>container.err.log ||
fail 16 "Docker container #$RUN exited $?"
diff -u test.sh container.out.log || fail 17 "Container #$RUN stdout mismatch"
diff -u test.sh mnt/tmp0/cat.log || fail 19 "Container #$RUN cat.log mismatch"
systemctl --user stop "$MOUNT_SVC"
done
printf "\nSuccess.\n" >&2
(6-6/12)