Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
perf(prefix): seed a new prefix by moving the cloned template in (#1599)
Raystorms74e5b86a33e8
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex fa369b0..0e2f51a 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -1950,6 +1950,7 @@ in_template_env() {seed_scratch=""seed_building=0+seed_merging=0# shellcheck disable=SC2329 # the traps in seed_prefix_from_template invoke thisabandon_seed() {if [ -n "$seed_scratch" ]; then@@ -1957,7 +1958,10 @@ abandon_seed() {in_template_env "$seed_scratch" "$WINESERVER" -k >/dev/null 2>&1 || truein_template_env "$seed_scratch" "$WINESERVER" -w >/dev/null 2>&1 || exit "$1"fi- rm -rf "$seed_scratch" 2>/dev/null || true+ # Half moved into the prefix: finish now, or keep the rest for the next launch to finish.+ if [ "$seed_merging" -eq 0 ] || { unnest_seed_entry && merge_seed_tree move; }; then+ rm -rf "$seed_scratch" 2>/dev/null || true+ fifiexit "$1"}@@ -2040,7 +2044,65 @@ build_prefix_template() {[ -f "$template_dir/pfx/system.reg" ]}-install_seed_tree() (+# Puts back a staged folder that mv put inside a folder that appeared at its name since the+# check. Each folder move is noted first, so this also works after a launch killed mid-move.+unnest_seed_entry() {+ placing="$seed_scratch/.notproton-seed-placing"+ [ -s "$placing" ] || return 0+ # Cut short while it was noted, so the move never started.+ { read -r staged && read -r source && read -r target; } < "$placing" || { : > "$placing"; return 0; }+ case "$source:$target" in "$seed_scratch"/*:"$WINEPREFIX"/*) ;; *) return 1 ;; esac+ nested="$target/${source##*/}"+ if [ "$(stat -f %i "$target" 2>/dev/null)" != "$staged" ] \+ && [ "$(stat -f %i "$nested" 2>/dev/null)" = "$staged" ]; then+ mv -n "$nested" "$source" && [ ! -e "$nested" ] || return 1+ fi+ : > "$placing"+}++# Puts one staged entry at a free name in the prefix, never over something that appeared+# there since the check: link(2) and symlink(2) refuse an existing name, and a folder that+# appeared takes ours inside it, which goes back to staging.+place_seed_entry() {+ if [ -d "$1" ] && [ ! -L "$1" ]; then+ staged=$(stat -f %i "$1") || return 1+ printf '%s\n%s\n%s\n' "$staged" "$1" "$2" > "$seed_scratch/.notproton-seed-placing" || return 1+ mv -n "$1" "$2" || return 1+ if [ "$(stat -f %i "$2" 2>/dev/null)" = "$staged" ]; then+ : > "$seed_scratch/.notproton-seed-placing"+ return 0+ fi+ unnest_seed_entry+ return 1+ elif [ -L "$1" ]; then+ link=$(readlink "$1") || return 1+ ln -sh "$link" "$2" || return 1+ if [ -L "$2" ] && [ "$(readlink "$2")" = "$link" ]; then+ rm -f "$1"+ return+ fi+ # ln made it inside a folder that appeared at $2, named after the link's target.+ nested="$2/${link##*/}"+ [ ! -L "$nested" ] || [ "$(readlink "$nested")" != "$link" ] || rm -f "$nested"+ return 1+ else+ ln -h "$1" "$2" || return 1+ if [ ! -L "$2" ] && [ "$1" -ef "$2" ]; then+ rm -f "$1"+ return+ fi+ [ ! "$1" -ef "$2/${1##*/}" ] || rm -f "$2/${1##*/}"+ return 1+ fi+}++# Moves the cloned template into the prefix, one rename per entry. It only descends into+# folders the prefix already has (the Steam profile and dosdevices), so most of the tree+# moves at once. "check" moves nothing and fails where "move" would. system.reg goes in+# last: until it does, the prefix is not seeded.+merge_seed_tree() (+ mode=$1+ same_volume "$seed_scratch" "$WINEPREFIX" || return 1set -- ""while [ "$#" -gt 0 ]; dorelative=$1@@ -2053,38 +2115,41 @@ install_seed_tree() ([ -e "$source" ] || [ -L "$source" ] || continuename=${source##*/}if [ -z "$relative" ]; then- case "$name" in system.reg|.update-timestamp) continue ;; esac+ case "$name" in+ system.reg|.update-timestamp|.notproton-seed-*) continue ;;+ esacfitarget="$target_dir/$name"- if [ -d "$source" ] && [ ! -L "$source" ]; then- if [ ! -e "$target" ] && [ ! -L "$target" ]; then- mkdir "$target" || return 1- fi+ if [ ! -e "$target" ] && [ ! -L "$target" ]; then+ [ -w "$target_dir" ] || return 1+ [ "$mode" = check ] || place_seed_entry "$source" "$target" || return 1+ elif [ -d "$source" ] && [ ! -L "$source" ]; then[ -d "$target" ] && [ ! -L "$target" ] || return 1set -- "$@" "$relative/$name"- elif [ -e "$target" ] || [ -L "$target" ]; then+ elsecase "$relative/$name" in/drive_c/users/steamuser/*) continue ;;esac+ # Linked in by a launch killed before it removed the staged name.+ [ ! -L "$source" ] && [ "$source" -ef "$target" ] && continue[ -L "$source" ] && [ -L "$target" ] \&& [ "$(readlink "$source")" = "$(readlink "$target")" ] || return 1- elif [ -L "$source" ]; then- ln -sh "$(readlink "$source")" "$target" || return 1- [ -L "$target" ] && [ "$(readlink "$source")" = "$(readlink "$target")" ] || return 1- elif [ -f "$source" ]; then- ln -h "$source" "$target" || return 1- [ ! -L "$target" ] && [ "$source" -ef "$target" ] || return 1- else- return 1fidonedone- ln -h "$seed_scratch/system.reg" "$WINEPREFIX/system.reg" \- && [ ! -L "$WINEPREFIX/system.reg" ] \- && [ "$seed_scratch/system.reg" -ef "$WINEPREFIX/system.reg" ] || return 1- if [ -f "$seed_scratch/.update-timestamp" ]; then- ln -h "$seed_scratch/.update-timestamp" "$WINEPREFIX/.update-timestamp" || return 1- fi+ for name in system.reg .update-timestamp; do+ source="$seed_scratch/$name"+ target="$WINEPREFIX/$name"+ if [ -f "$source" ] && [ ! -L "$source" ] && [ "$source" -ef "$target" ]; then+ [ "$mode" = check ] || rm -f "$source" || return 1+ elif [ -f "$source" ] && [ ! -L "$source" ]; then+ [ ! -e "$target" ] && [ ! -L "$target" ] && [ -w "$WINEPREFIX" ] || return 1+ [ "$mode" = check ] || place_seed_entry "$source" "$target" || return 1+ elif [ -e "$source" ] || [ -L "$source" ]; then+ return 1+ fi+ done+ [ "$mode" = check ] || { [ -f "$WINEPREFIX/system.reg" ] && [ ! -L "$WINEPREFIX/system.reg" ]; })copy_template_into_prefix() {@@ -2101,8 +2166,25 @@ copy_template_into_prefix() {how="copied this prefix from the $runner_id template, not a clone"cp -R "$template_dir/pfx/." "$seed_scratch" 2>/dev/null && copied=0 || copied=$?fi- if [ "$copied" -eq 0 ] && prefix_is_bare && install_seed_tree; then- echo "=== $how ===" >> "$log" 2>&1 || true+ # Files go in as hard links. Without them (exFAT, some network shares), back off before+ # anything moves or is recorded for a later launch to finish; staging is on the prefix's+ # volume. The target lets a later launch finish a merge this one could not, into this+ # prefix only. It is the inode alone: an external drive can come back with another+ # device number.+ if [ "$copied" -eq 0 ] \+ && ! ln "$seed_scratch/system.reg" "$seed_scratch/.notproton-seed-link" 2>/dev/null; then+ echo "=== this volume has no hard links, wine builds this prefix itself ===" >> "$log" 2>&1 || true+ elif [ "$copied" -eq 0 ] && prefix_is_bare \+ && stat -f %i "$WINEPREFIX" > "$seed_scratch/.notproton-seed-target" 2>/dev/null \+ && merge_seed_tree check; then+ seed_merging=1+ if merge_seed_tree move; then+ echo "=== $how ===" >> "$log" 2>&1 || true+ else+ echo "=== could not finish seeding from the template, wine completes this prefix ===" \+ >> "$log" 2>&1 || true+ fi+ seed_merging=0elseecho "=== could not seed from the template, wine builds this prefix itself ===" \>> "$log" 2>&1 || true@@ -2111,6 +2193,42 @@ copy_template_into_prefix() {seed_scratch=""}+# A launch killed while it moved the template in left the rest in its staging folder.+finish_dead_seeds() {+ dropping=""+ for leftover in "$STEAM_COMPAT_DATA_PATH"/pfx.seeding.*; do+ [ -d "$leftover" ] && [ ! -L "$leftover" ] || continue+ case "${leftover##*.}" in ''|0|*[!0-9]*) continue ;; esac+ [ "$(stat -f %u "$leftover" 2>/dev/null)" = "$(id -u)" ] || continue+ kill -0 "${leftover##*.}" 2>/dev/null && continue+ if [ ! -f "$leftover/.notproton-seed-target" ]; then+ why="it stopped before it moved anything in"+ elif [ "$(cat "$leftover/.notproton-seed-target" 2>/dev/null)" \+ != "$(stat -f %i "$WINEPREFIX" 2>/dev/null)" ]; then+ why="it was for a prefix that has been replaced since"+ elif ! same_volume "$leftover" "$WINEPREFIX"; then+ why="it is not on the prefix's volume"+ else+ seed_scratch=$leftover+ if unnest_seed_entry && merge_seed_tree check && merge_seed_tree move; then+ echo "=== finished seeding this prefix, which an earlier launch left half done ===" \+ >> "$log" 2>&1 || true+ why=""+ else+ why="it could not be finished, wine completes this prefix"+ fi+ seed_scratch=""+ fi+ [ -z "$why" ] || dropping="$dropping${leftover##*/}|$why+"+ done+ sweep_dead_seeds "$STEAM_COMPAT_DATA_PATH"/pfx.seeding.*+ printf '%s' "$dropping" | while IFS='|' read -r name why; do+ [ ! -e "$STEAM_COMPAT_DATA_PATH/$name" ] || continue+ echo "=== dropped $name, an earlier launch's unfinished seed: $why ===" >> "$log" 2>&1 || true+ done+}+prefix_is_bare() (set -- ""while [ "$#" -gt 0 ]; do@@ -2161,7 +2279,7 @@ template_identity() (# Each game's prefix is copied from one template (per runner) instead of running wineboot.# On APFS the copy is a clone, so it takes almost no space.seed_prefix_from_template() {- sweep_dead_seeds "$STEAM_COMPAT_DATA_PATH"/pfx.seeding.*+ finish_dead_seeds[ -n "$runner_id" ] || return 0if ! prefix_is_bare; then[ -f "$WINEPREFIX/system.reg" ] \diff --git a/dylib/tests/seedcheck.sh b/dylib/tests/seedcheck.shindex 9b02b49..c0be224 100644--- a/dylib/tests/seedcheck.sh+++ b/dylib/tests/seedcheck.sh@@ -3,7 +3,12 @@ set -euSRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"work=$(mktemp -d "${TMPDIR:-/tmp}/np-seedcheck.XXXXXX")test "$(stat -f %d "$work")" = "$(stat -f %d "${TMPDIR:-/tmp}")"-trap 'chmod -R u+rwX "$work"; rm -rf "$work"' EXIT+detach_images() {+ for mounted in "$work"/mnt.*; do+ [ ! -d "$mounted" ] || /usr/bin/hdiutil detach -quiet -force "$mounted" 2>/dev/null || true+ done+}+trap 'detach_images; chmod -R u+rwX "$work"; rm -rf "$work"' EXITcut_block() {from="$1" to="$2" keep="$3" awk 'BEGIN { from = ENVIRON["from"]; to = ENVIRON["to"]; keep = ENVIRON["keep"] }@@ -90,41 +95,226 @@ check test -f "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"check test -f "$WINEPREFIX/.update-timestamp"check test -f "$WINEPREFIX/system.reg"check test ! "$template_dir/pfx/drive_c/windows/ntdll.dll" -ef "$WINEPREFIX/drive_c/windows/ntdll.dll"-printf changed > "$WINEPREFIX/drive_c/windows/ntdll.dll"+check test "$(stat -f %l "$WINEPREFIX/drive_c/windows/ntdll.dll")" = 1+check test "$(stat -f %l "$WINEPREFIX/system.reg")" = 1+check test ! -e "$WINEPREFIX/.notproton-seed-target"+check test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 0+check test "$(find "$template_dir/pfx" | wc -l)" -eq "$(find "$WINEPREFIX" -path "$WINEPREFIX/drive_c/users/steamuser/Documents/Game*" -prune -o -print | wc -l)"+first_prefix="$WINEPREFIX"+STEAM_COMPAT_DATA_PATH="$case_root/next-game"+WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"+mkdir -p "$WINEPREFIX"+copy_template_into_prefix+check test ! "$first_prefix/drive_c/windows/ntdll.dll" -ef "$WINEPREFIX/drive_c/windows/ntdll.dll"+printf changed > "$first_prefix/drive_c/windows/ntdll.dll"+printf changed >> "$first_prefix/system.reg"check test "$(cat "$template_dir/pfx/drive_c/windows/ntdll.dll")" = dll+check test "$(cat "$WINEPREFIX/drive_c/windows/ntdll.dll")" = dll+check test "$(cat "$template_dir/pfx/system.reg")" = reg+check test "$(cat "$WINEPREFIX/system.reg")" = reg++# Killed after it put $1 entries in, or with $2 set, between linking a file in and removing+# its staged name: the launch and its merge both die on the spot.+kill_seed_after() {+ env functions="$functions" moves="$1" on_rm="${2:-}" /bin/sh -c "+ eval \"\$functions\"+ die() { kill -KILL \"\$\$\"; exec /usr/bin/true; }+ count() {+ [ \"\$moves\" -gt 0 ] || die+ moves=\$((moves - 1))+ }+ mv() { count; command mv \"\$@\"; }+ ln() {+ for destination; do :; done+ case \"\$destination\" in */.notproton-seed-link) ;; *) count ;; esac+ command ln \"\$@\"+ }+ rm() { if [ -n \"\$on_rm\" ] && [ \"\$1\" = -f ]; then die; fi; command rm \"\$@\"; }+ copy_template_into_prefix+ "+}+seeded_whole() {+ test -f "$WINEPREFIX/system.reg" && test -f "$WINEPREFIX/.update-timestamp" \+ && test "$(cat "$WINEPREFIX/drive_c/windows/ntdll.dll")" = dll \+ && test "$(readlink "$WINEPREFIX/drive_c/users/crossover")" = steamuser \+ && test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav")" = save \+ && test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 0+}+for moved in 0 1 2; do+ fixture+ mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+ printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+ interrupted_status=0+ { kill_seed_after "$moved"; } 2>/dev/null || interrupted_status=$?+ check test "$interrupted_status" -eq 137+ check test ! -e "$WINEPREFIX/system.reg"+ check test -f "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+ check test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 1+ seed_prefix_from_template+ check seeded_whole+ check grep -q 'finished seeding this prefix' "$log"+donefixturemkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"-interrupted_status=0-env functions="$functions" /bin/sh -c "- eval \"\$functions\"- ln() { command ln \"\$@\"; kill -KILL \"\$\$\"; return 1; }+{ kill_seed_after 99 on-rm; } 2>/dev/null || true+check test "$STEAM_COMPAT_DATA_PATH"/pfx.seeding.*/user.reg -ef "$WINEPREFIX/user.reg"+check test ! -e "$WINEPREFIX/system.reg"+finish_dead_seeds+check seeded_whole+check grep -q 'finished seeding this prefix' "$log"++# A save that appears after the check is never replaced by the template's file.+fixture+mkdir -p "$template_dir/pfx/drive_c/users/steamuser/Documents/Game" \+ "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+printf template > "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/slot.sav"+(+ eval 'ln() {+ for destination; do :; done+ case "$destination" in */pfx/drive_c/users/steamuser/Documents/Game/slot.sav)+ printf player > "$destination" ;;+ esac+ command ln "$@"+ }'copy_template_into_prefix-" || interrupted_status=$?-check test "$interrupted_status" -eq 137-check test -f "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"-check test ! -e "$WINEPREFIX/.update-timestamp"+) 2>/dev/null+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav")" = playercheck test ! -e "$WINEPREFIX/system.reg"-for abandoned in "$STEAM_COMPAT_DATA_PATH"/pfx.seeding.*; do- check test -d "$abandoned"- seed_prefix_from_template- check test ! -e "$abandoned"++# A folder that appears where a file or link goes is left as the player made it.+for entry in file link; do+ fixture+ profile="$WINEPREFIX/drive_c/users/steamuser"+ mkdir -p "$template_dir/pfx/drive_c/users/steamuser/Documents/Game" "$profile/Documents/Game"+ printf template > "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/slot.sav"+ [ "$entry" = file ] && racing="$profile/Documents/Game/slot.sav" || racing="$profile/My Documents"+ (+ eval 'ln() {+ for destination; do :; done+ [ "$destination" != "$racing" ] || mkdir "$destination"+ command ln "$@"+ }'+ copy_template_into_prefix+ ) 2>/dev/null+ check test -d "$racing"+ check test "$(find "$racing" | wc -l | tr -d ' ')" = 1+ check test ! -e "$WINEPREFIX/system.reg"done+# A link the player already had in that folder stays.fixture-mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"-printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"-interrupted_status=0+profile="$WINEPREFIX/drive_c/users/steamuser"+mkdir -p "$profile/Documents/Game"+(+ eval 'ln() {+ for destination; do :; done+ if [ "$destination" = "$profile/My Documents" ]; then+ mkdir "$destination" && command ln -s ./Documents "$destination/Documents"+ fi+ command ln "$@"+ }'+ copy_template_into_prefix+) 2>/dev/null+check test "$(readlink "$profile/My Documents/Documents")" = ./Documents+check test ! -e "$WINEPREFIX/system.reg"++# Nor does a folder that appears after the check end up holding the template's inside it.+fixture+mkdir -p "$template_dir/pfx/drive_c/users/steamuser/Documents/Game" \+ "$WINEPREFIX/drive_c/users/steamuser/Documents"+printf template > "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/default.ini"+(+ eval 'mv() {+ for destination; do :; done+ case "$destination" in */pfx/drive_c/users/steamuser/Documents/Game)+ mkdir "$destination" && printf player > "$destination/slot.sav" ;;+ esac+ command mv "$@"+ }'+ copy_template_into_prefix+) 2>/dev/null+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav")" = player+check test ! -e "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/Game"+check test ! -e "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/default.ini"+check test ! -e "$WINEPREFIX/system.reg"+check test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 0++# Killed right after mv put the folder inside the one that appeared, before it could check:+# the next launch puts it back and merges it with the player's.+fixture+mkdir -p "$template_dir/pfx/drive_c/users/steamuser/Documents/Game" \+ "$WINEPREFIX/drive_c/users/steamuser/Documents"+printf template > "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/default.ini"env functions="$functions" /bin/sh -c "eval \"\$functions\"- ln() { command ln \"\$@\"; kill -TERM \"\$\$\"; return 1; }- trap 'abandon_seed 143' TERM+ mv() {+ for destination; do :; done+ case \"\$destination\" in */pfx/drive_c/users/steamuser/Documents/Game)+ mkdir \"\$destination\" && printf player > \"\$destination/slot.sav\"+ command mv \"\$@\"+ kill -KILL \"\$\$\"+ exec /usr/bin/true ;;+ esac+ command mv \"\$@\"+ }copy_template_into_prefix-" || interrupted_status=$?-check test "$interrupted_status" -eq 143-check test -f "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"-check test ! -e "$WINEPREFIX/.update-timestamp"+" 2>/dev/null || true+check test -e "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/Game"+finish_dead_seeds+check test ! -e "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/Game"+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav")" = player+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/default.ini")" = template+check test -f "$WINEPREFIX/system.reg"+check test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 0++# A prefix rebuilt since the seed was killed is seeded again, not finished with the leftovers.+fixture+mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+{ kill_seed_after 1; } 2>/dev/null || true+mv "$WINEPREFIX" "$case_root/old-pfx"+mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+finish_dead_seeds+check prefix_is_bare+copy_template_into_prefix+check seeded_whole+check test ! -e "$case_root/old-pfx/system.reg"+check test "$(grep -c 'finished seeding this prefix' "$log" || true)" = 0+check grep -q 'dropped pfx.seeding.[0-9]*, an earlier launch.s unfinished seed: it was for a prefix that has been replaced since' "$log"++# Killed while cloning, before the merge: the prefix was never touched.+fixture+mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+/bin/sh -c 'exit 0' &+dead=$!+wait "$dead"+mkdir "$STEAM_COMPAT_DATA_PATH/pfx.seeding.$dead"+printf partial > "$STEAM_COMPAT_DATA_PATH/pfx.seeding.$dead/system.reg"+finish_dead_seeds+check grep -q "dropped pfx.seeding.$dead, an earlier launch's unfinished seed: it stopped before it moved anything in" "$log"+check prefix_is_bare+copy_template_into_prefix+check seeded_whole+check test "$(cat "$WINEPREFIX/system.reg")" = reg++for signal in TERM:143 INT:130 HUP:129; do+ fixture+ mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+ printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+ interrupted_status=0+ env functions="$functions" signal="${signal%:*}" status="${signal#*:}" /bin/sh -c "+ eval \"\$functions\"+ mv() { command mv \"\$@\"; kill -\"\$signal\" \"\$\$\"; }+ trap \"abandon_seed \$status\" \"\$signal\"+ copy_template_into_prefix+ " || interrupted_status=$?+ check test "$interrupted_status" -eq "${signal#*:}"+ check seeded_whole+donefixturemkdir -p "$template_dir/pfx.building.$$"@@ -184,11 +374,128 @@ fixturemkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"printf original > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/save"(- eval 'ln() { return 1; }'+ eval 'mv() { return 1; }'copy_template_into_prefix)check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/save")" = originalcheck test ! -e "$WINEPREFIX/system.reg"+check test ! -e "$WINEPREFIX/drive_c/windows"+check test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 0++# Attaches a fresh disk image of file system $1 at $work/mnt.$2.+attach_image() {+ [ -f "$work/$2.dmg" ] \+ || /usr/bin/hdiutil create -quiet -size 32m -fs "$1" -volname "np-$2" "$work/$2.dmg" || return 1+ mkdir -p "$work/mnt.$2"+ /usr/bin/hdiutil attach -quiet -nobrowse -mountpoint "$work/mnt.$2" "$work/$2.dmg"+}+no_image() {+ printf ' FAIL could not attach a %s disk image, %s did not run\n' "$1" "$2"+ fails=$((fails + 1))+}++# A library on another volume, here HFS+, gets a full copy that shares nothing with the template.+fixture+if ! attach_image HFS+ hfs; then+ no_image HFS+ "the other-volume seed"+else+ check test "$(stat -f %d "$work/mnt.hfs")" != "$(stat -f %d "$template_dir")"+ STEAM_COMPAT_DATA_PATH="$work/mnt.hfs/game"+ WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"+ mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+ printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+ copy_template_into_prefix+ check seeded_whole+ check grep -q 'copied this prefix from the .* template, not a clone' "$log"+ check test "$(stat -f %l "$WINEPREFIX/drive_c/windows/ntdll.dll")" = 1+ printf changed > "$WINEPREFIX/drive_c/windows/ntdll.dll"+ check test "$(cat "$template_dir/pfx/drive_c/windows/ntdll.dll")" = dll+ /usr/bin/hdiutil detach -quiet -force "$work/mnt.hfs"+fi++# An external drive can come back with another device number: a seed killed on it is still+# finished by the next launch.+fixture+if ! attach_image HFS+ drive; then+ no_image HFS+ "the re-plugged drive seed"+else+ STEAM_COMPAT_DATA_PATH="$work/mnt.drive/game"+ WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"+ mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+ printf save > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/slot.sav"+ { kill_seed_after 1; } 2>/dev/null || true+ check test ! -e "$WINEPREFIX/system.reg"+ plugged=$(stat -f %d "$work/mnt.drive")+ /usr/bin/hdiutil detach -quiet -force "$work/mnt.drive"+ # Another disk takes the drive's old device node while it is away.+ attach_image HFS+ other || true+ if ! attach_image HFS+ drive; then+ no_image HFS+ "the re-plugged drive seed"+ else+ check test "$(stat -f %d "$work/mnt.drive")" != "$plugged"+ finish_dead_seeds+ check seeded_whole+ check grep -q 'finished seeding this prefix' "$log"+ /usr/bin/hdiutil detach -quiet -force "$work/mnt.drive"+ fi+ [ ! -d "$work/mnt.other" ] || /usr/bin/hdiutil detach -quiet -force "$work/mnt.other" 2>/dev/null || true+fi++# A volume without hard links (exFAT) is left as it was, so Wine builds the prefix as before.+# The prefix is empty: macOS gives every entry made on exFAT a ._ companion, which a prefix+# holding saves already fails prefix_is_bare on.+fixture+if ! attach_image ExFAT exfat; then+ no_image exFAT "the seed without hard links"+else+ STEAM_COMPAT_DATA_PATH="$work/mnt.exfat/game"+ WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"+ mkdir -p "$WINEPREFIX"+ check prefix_is_bare+ copy_template_into_prefix+ check grep -q 'this volume has no hard links' "$log"+ check test -z "$(ls -A "$WINEPREFIX")"+ # Killed right after it recorded the prefix: the next launch has nothing to finish there.+ : > "$log"+ { env functions="$functions" /bin/sh -c "+ eval \"\$functions\"+ stat() {+ command stat \"\$@\"+ [ \"\$2:\$3\" != \"%i:\$WINEPREFIX\" ] || { kill -KILL \"\$\$\"; exec /usr/bin/true; }+ }+ copy_template_into_prefix+ "; } 2>/dev/null || true+ finish_dead_seeds+ check test -z "$(ls -A "$WINEPREFIX")"+ check test "$(grep -c 'finished seeding this prefix' "$log" || true)" = 0+ check test "$(find "$STEAM_COMPAT_DATA_PATH" -maxdepth 1 -name 'pfx.seeding.*' | wc -l | tr -d ' ')" = 0+ /usr/bin/hdiutil detach -quiet -force "$work/mnt.exfat"+fi++# A conflict anywhere moves nothing in.+fixture+mkdir -p "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+printf original > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/save"+printf file > "$WINEPREFIX/drive_c/users/steamuser/AppData"+copy_template_into_prefix+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/save")" = original+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/AppData")" = file+check test ! -e "$WINEPREFIX/drive_c/windows"+check test ! -e "$WINEPREFIX/system.reg"+check test ! -e "$WINEPREFIX/drive_c/users/steamuser/Desktop"++# The player's files win over the template's, as they always did.+fixture+mkdir -p "$template_dir/pfx/drive_c/users/steamuser/Documents/Game" \+ "$WINEPREFIX/drive_c/users/steamuser/Documents/Game"+printf template > "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/save"+printf template > "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/other"+printf player > "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/save"+copy_template_into_prefix+check test -f "$WINEPREFIX/system.reg"+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/save")" = player+check test "$(cat "$WINEPREFIX/drive_c/users/steamuser/Documents/Game/other")" = template+check test "$(cat "$template_dir/pfx/drive_c/users/steamuser/Documents/Game/save")" = templatefixturemkdir -p "$WINEPREFIX/dosdevices"