From b67ae34ca1b989fe3a9badb46d03eea44596cb3c Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sun, 8 Nov 2026 19:02:26 +0000 Subject: [PATCH] Stage ntfy output on installation filesystem before atomic replacement --- scripts/setup-native.py | 7 +++++-- scripts/test_setup_native.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/setup-native.py b/scripts/setup-native.py index 4b1994c2..7ed9bdde 100644 --- a/scripts/setup-native.py +++ b/scripts/setup-native.py @@ -571,7 +571,10 @@ class Setup: source = Path(cache.stdout.strip()) / f"{module}@{version}" if not source.is_dir(): raise ValueError(f"the Go module cache has no source for {pinned}") - with tempfile.TemporaryDirectory(prefix="pipelines-ntfy-") as temporary: + # Keep source work in the system temp directory, but stage the output + # beside the destination: /tmp may be a different filesystem on Linux. + with tempfile.TemporaryDirectory(prefix="pipelines-ntfy-") as temporary, \ + tempfile.TemporaryDirectory(prefix=".ntfy-", dir=path.parent) as staging: checkout = Path(temporary) / "src" shutil.copytree(source, checkout, symlinks=True) # The module cache is read-only and carries no built web assets; the @@ -581,7 +584,7 @@ class Setup: (checkout / "server/site").mkdir(parents=True, exist_ok=True) (checkout / "server/docs/index.html").touch() (checkout / "server/site/app.html").touch() - built = Path(temporary) / "ntfy" + built = Path(staging) / "ntfy" env = dict(self.environ) env["CGO_ENABLED"] = "1" build = self.runner( diff --git a/scripts/test_setup_native.py b/scripts/test_setup_native.py index 322d22d0..8a74f682 100644 --- a/scripts/test_setup_native.py +++ b/scripts/test_setup_native.py @@ -516,6 +516,29 @@ class SetupNativeTests(unittest.TestCase): if call[:2] == ["go", "build"] and call[-1] == ".") self.assertEqual(kwargs.get("env", {}).get("CGO_ENABLED"), "1") + def test_ntfy_install_handles_system_temp_on_another_filesystem(self): + with tempfile.TemporaryDirectory() as directory: + installer = self.installer(directory, Recorder()) + prefix = Path(directory) / "prefix" + installer.prepare_layout(prefix) + installed = prefix / "bin/ntfy" + installed.write_bytes(b"previous binary") + replace = os.replace + + def cross_device_guard(source, destination): + # Model /tmp on a separate mount from the installation prefix. + if not Path(source).is_relative_to(prefix / "bin"): + import errno + raise OSError(errno.EXDEV, "Invalid cross-device link") + return replace(source, destination) + + with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \ + patch.object(setup_native.os, "replace", side_effect=cross_device_guard): + installer.build_ntfy(prefix, resolution()) + self.assertNotEqual(installed.read_bytes(), b"previous binary") + self.assertEqual(installed.stat().st_mode & 0o777, 0o755) + self.assertEqual(list((prefix / "bin").glob(".ntfy-*")), []) + def test_ntfy_build_is_reused_for_the_same_version(self): with tempfile.TemporaryDirectory() as directory: recorder = Recorder() @@ -541,9 +564,13 @@ class SetupNativeTests(unittest.TestCase): installer = self.installer(directory, Recorder(fail_build=True)) prefix = Path(directory) / "prefix" installer.prepare_layout(prefix) + installed = prefix / "bin/ntfy" + installed.write_bytes(b"previous binary") with patch.object(setup_native.shutil, "which", side_effect=self.which_all()): with self.assertRaisesRegex(ValueError, "build failed"): installer.build_ntfy(prefix, resolution()) + self.assertEqual(installed.read_bytes(), b"previous binary") + self.assertEqual(list((prefix / "bin").glob(".ntfy-*")), []) def test_publisher_token_is_never_overwritten(self): with tempfile.TemporaryDirectory() as directory: