diff --git a/apps/gridcraft/src/nightly_session.rs b/apps/gridcraft/src/nightly_session.rs index 5b84f81e6..597bb4b2a 100644 --- a/apps/gridcraft/src/nightly_session.rs +++ b/apps/gridcraft/src/nightly_session.rs @@ -300,9 +300,11 @@ mod tests { // regular_or_missing refuses an alias outright; the temporary writer is what a first write // uses, and it never follows one either. assert!(Session::begin(Some(&fixture.0), version()).is_err()); - atomic_write_no_follow(&fixture.0.join("record.json"), b"ours").unwrap(); - assert_eq!(std::fs::read(fixture.0.join("record.json")).unwrap(), b"ours"); + // The link is at RECORD itself: writing there must replace the alias, not follow it. + atomic_write_no_follow(&fixture.0.join(RECORD), b"ours").unwrap(); + assert_eq!(std::fs::read(fixture.0.join(RECORD)).unwrap(), b"ours"); + assert!(!fixture.0.join(RECORD).is_symlink(), "the alias must be replaced, not written through"); assert_eq!(std::fs::read(&external).unwrap(), b"stable bytes"); - assert!(!fixture.0.join(".record.json.new").exists()); + assert!(!fixture.0.join(".nightly-session.json.new").exists()); } } diff --git a/apps/gridcraft/src/profile_root.rs b/apps/gridcraft/src/profile_root.rs index 8ebbe72e4..d911a3fa4 100644 --- a/apps/gridcraft/src/profile_root.rs +++ b/apps/gridcraft/src/profile_root.rs @@ -181,10 +181,17 @@ pub fn control_directory(root: &Path) -> Result { /// The app's own exclusive writable probe: create a file inside the profile, then remove it. pub fn ensure_writable(root: &Path) -> std::io::Result<()> { static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); - let probe = root.join(format!(".gridcraft-nightly-writable-{}-{}", std::process::id(), NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed))); - let result = std::fs::OpenOptions::new().write(true).create_new(true).open(&probe).map(drop); - let _ = std::fs::remove_file(&probe); - result + // A crashed launch can leave a probe with this name behind: take the next one instead of + // failing, and remove only the file this call created, never someone else's. + loop { + let probe = + root.join(format!(".gridcraft-nightly-writable-{}-{}", std::process::id(), NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed))); + match std::fs::OpenOptions::new().write(true).create_new(true).open(&probe) { + Ok(_) => return std::fs::remove_file(&probe), + Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue, + Err(error) => return Err(error), + } + } } /// The writable hook is injected so filesystem boundary tests exercise the real policy without diff --git a/packaging/linux/nightly-arch-launch.sh b/packaging/linux/nightly-arch-launch.sh index e208b50f4..ef22eea05 100755 --- a/packaging/linux/nightly-arch-launch.sh +++ b/packaging/linux/nightly-arch-launch.sh @@ -4,17 +4,18 @@ # settings, logs, the control token and the session record, so no XDG variable has to move. set -eu -if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then - echo "gridcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2 - exit 2 -fi - real_bin="$(dirname "$0")/.gridcraft-nightly/gridcraft" +# The Launcher's protocol and a bare version query name their own root and never read the default +# one, so they are dispatched before the guard that a default-root launch needs. case "${1-}" in --launch-profile | --profile-root) exec "$real_bin" "$@" ;; esac if [ "$#" -eq 1 ] && { [ "${1-}" = "--version" ] || [ "${1-}" = "-V" ]; }; then exec "$real_bin" "$@" fi +if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then + echo "gridcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2 + exit 2 +fi exec "$real_bin" --launch-profile nightly-v1 \ --profile-root "${XDG_DATA_HOME:-$HOME/.local/share}/gridcraft-nightly/profile" -- "$@" diff --git a/packaging/linux/nightly-launch.sh b/packaging/linux/nightly-launch.sh index a5ac4f69f..48e120705 100755 --- a/packaging/linux/nightly-launch.sh +++ b/packaging/linux/nightly-launch.sh @@ -20,15 +20,16 @@ if [ -z "$real" ]; then echo "gridcraft-nightly: no GridCraft binary beside $0 (usr/bin/gridcraft, gridcraft-bin)" >&2 exit 2 fi -if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then - echo "gridcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2 - exit 2 -fi -# A bare version query and the Launcher's own protocol pass straight through. +# A bare version query and the Launcher's own protocol pass straight through: neither needs a data +# folder of this script's own, so neither may be refused for a HOME it never reads. case "${1-}" in --launch-profile | --profile-root) exec "$real" "$@" ;; esac if [ "$#" -eq 1 ] && { [ "${1-}" = "--version" ] || [ "${1-}" = "-V" ]; }; then exec "$real" "$@" fi +if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then + echo "gridcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2 + exit 2 +fi exec "$real" --launch-profile nightly-v1 --profile-root "${XDG_DATA_HOME:-$HOME/.local/share}/gridcraft-nightly/profile" -- "$@" diff --git a/packaging/windows/nightly.ps1 b/packaging/windows/nightly.ps1 index a23b58f5a..1d2312d9c 100644 --- a/packaging/windows/nightly.ps1 +++ b/packaging/windows/nightly.ps1 @@ -84,7 +84,8 @@ try { $env:GRIDCRAFT_BUILD_CHANNEL = 'nightly-v1' $env:GRIDCRAFT_REQUIRE_WINRES = '1' $env:CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS = '-C target-feature=+crt-static' - cargo build --release --locked -p gridcraft --target $Target + # Into the directory the archive steps read (`$TargetDir`), not Cargo's default. + cargo build --release --locked -p gridcraft --target $Target --target-dir $TargetDir if ($LASTEXITCODE -ne 0) { throw "nightly cargo build failed: $LASTEXITCODE" } } finally { $env:GRIDCRAFT_BUILD_CHANNEL = $oldChannel