mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-02 02:33:55 -06:00
nightly: fix the launcher, Windows build and profile-probe review findings
- Both Linux launchers dispatch the Launcher's protocol and a bare version query before the XDG_DATA_HOME/HOME guard, so neither is refused for a HOME it never reads. - `nightly.ps1` builds into the `-TargetDir` its archive steps read. - The writable probe retries on a leftover file with its name and removes only the file it created. - The planted-record-link test writes at RECORD rather than a sibling name, so it exercises the alias it plants.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,10 +181,17 @@ pub fn control_directory(root: &Path) -> Result<PathBuf, String> {
|
||||
/// 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
|
||||
|
||||
@@ -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" -- "$@"
|
||||
|
||||
@@ -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" -- "$@"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user