Stage ntfy output on installation filesystem before atomic replacement

This commit is contained in:
2026-11-08 19:02:26 +00:00
parent 323faef686
commit b67ae34ca1
2 changed files with 32 additions and 2 deletions
+27
View File
@@ -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: