Stage ntfy output on installation filesystem before atomic replacement
This commit is contained in:
@@ -571,7 +571,10 @@ class Setup:
|
|||||||
source = Path(cache.stdout.strip()) / f"{module}@{version}"
|
source = Path(cache.stdout.strip()) / f"{module}@{version}"
|
||||||
if not source.is_dir():
|
if not source.is_dir():
|
||||||
raise ValueError(f"the Go module cache has no source for {pinned}")
|
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"
|
checkout = Path(temporary) / "src"
|
||||||
shutil.copytree(source, checkout, symlinks=True)
|
shutil.copytree(source, checkout, symlinks=True)
|
||||||
# The module cache is read-only and carries no built web assets; the
|
# 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/site").mkdir(parents=True, exist_ok=True)
|
||||||
(checkout / "server/docs/index.html").touch()
|
(checkout / "server/docs/index.html").touch()
|
||||||
(checkout / "server/site/app.html").touch()
|
(checkout / "server/site/app.html").touch()
|
||||||
built = Path(temporary) / "ntfy"
|
built = Path(staging) / "ntfy"
|
||||||
env = dict(self.environ)
|
env = dict(self.environ)
|
||||||
env["CGO_ENABLED"] = "1"
|
env["CGO_ENABLED"] = "1"
|
||||||
build = self.runner(
|
build = self.runner(
|
||||||
|
|||||||
@@ -516,6 +516,29 @@ class SetupNativeTests(unittest.TestCase):
|
|||||||
if call[:2] == ["go", "build"] and call[-1] == ".")
|
if call[:2] == ["go", "build"] and call[-1] == ".")
|
||||||
self.assertEqual(kwargs.get("env", {}).get("CGO_ENABLED"), "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):
|
def test_ntfy_build_is_reused_for_the_same_version(self):
|
||||||
with tempfile.TemporaryDirectory() as directory:
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
recorder = Recorder()
|
recorder = Recorder()
|
||||||
@@ -541,9 +564,13 @@ class SetupNativeTests(unittest.TestCase):
|
|||||||
installer = self.installer(directory, Recorder(fail_build=True))
|
installer = self.installer(directory, Recorder(fail_build=True))
|
||||||
prefix = Path(directory) / "prefix"
|
prefix = Path(directory) / "prefix"
|
||||||
installer.prepare_layout(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 patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||||
with self.assertRaisesRegex(ValueError, "build failed"):
|
with self.assertRaisesRegex(ValueError, "build failed"):
|
||||||
installer.build_ntfy(prefix, resolution())
|
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):
|
def test_publisher_token_is_never_overwritten(self):
|
||||||
with tempfile.TemporaryDirectory() as directory:
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
|||||||
Reference in New Issue
Block a user