Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

fix(installer): refresh stale Hermes WSL file aliases (#8311)

Mike Bradleya1073a2adf8f
diff --git a/ods/scripts/refresh-hermes-mounts.py b/ods/scripts/refresh-hermes-mounts.py
index 62e0cb9f3..a53a0e028 100644
--- a/ods/scripts/refresh-hermes-mounts.py
+++ b/ods/scripts/refresh-hermes-mounts.py
@@ -57,8 +57,8 @@ def execute(argv, cwd, timeout=30):
raise Refused("Hermes mount verification command failed") from exc
-def desktop_data_source_matches(source, expected):
- """Prove a Desktop directory proxy aliases this installation's live data."""
+def desktop_source_matches(source, expected, is_expected_kind):
+ """Prove a Desktop proxy still aliases the installed source inode."""
if not isinstance(source, str) or not DESKTOP_FILE_SOURCE.fullmatch(source):
return False
distro, digest = source.rsplit("/", 2)[1:]
@@ -71,12 +71,20 @@ def desktop_data_source_matches(source, expected):
return False
actual = os.stat(visible, follow_symlinks=False)
wanted = os.stat(expected, follow_symlinks=False)
- return (stat.S_ISDIR(actual.st_mode) and stat.S_ISDIR(wanted.st_mode)
+ return (is_expected_kind(actual.st_mode) and is_expected_kind(wanted.st_mode)
and (actual.st_dev, actual.st_ino) == (wanted.st_dev, wanted.st_ino))
except (OSError, RuntimeError):
return False
+def desktop_data_source_matches(source, expected):
+ return desktop_source_matches(source, expected, stat.S_ISDIR)
+
+
+def desktop_file_source_matches(source, expected):
+ return desktop_source_matches(source, expected, stat.S_ISREG)
+
+
def host_digests(root):
result = {}
for destination, relative in FILES.items():
@@ -159,10 +167,24 @@ def refresh(root, docker, compose, run=execute):
raise Refused("Hermes file hashes could not be verified")
return values
+ def file_aliases_current(item):
+ # A running container can still read a deleted Desktop file alias.
+ # Equal bytes alone do not prove that Docker can mount it on restart.
+ # Native absolute paths are resolved again by Docker at startup; WSL
+ # proxies must still identify the installed file, not an old inode.
+ for destination, relative in FILES.items():
+ source = next(mount["Source"] for mount in item["Mounts"]
+ if mount["Destination"] == destination)
+ expected_path = root / relative
+ if source != str(expected_path) and not desktop_file_source_matches(source, expected_path):
+ return False
+ return True
+
expected = host_digests(root)
- identity = container()["Id"]
+ original = container()
+ identity = original["Id"]
before = observed(identity)
- if all(before[path] == value for path, value in expected.items()):
+ if all(before[path] == value for path, value in expected.items()) and file_aliases_current(original):
return "current"
# Recheck the installation and selected container immediately before the
# only mutation. Never repair an unreadable file or a changed ownership claim.
@@ -188,6 +210,8 @@ def refresh(root, docker, compose, run=execute):
after = observed(new_identity)
if host_digests(root) != expected or any(after[path] != value for path, value in expected.items()):
raise Refused("Hermes mounted files still differ after one recreation")
+ if not file_aliases_current(refreshed):
+ raise Refused("Hermes file aliases still differ after one recreation")
if before[LIVE_CONFIG] is not None and before[LIVE_CONFIG] != after[LIVE_CONFIG]:
raise Refused("Hermes live configuration changed during recreation; review before continuing")
return "refreshed"
diff --git a/ods/tests/test-phase11-hermes-mount-refresh.py b/ods/tests/test-phase11-hermes-mount-refresh.py
index e84e45a02..e20139eb4 100644
--- a/ods/tests/test-phase11-hermes-mount-refresh.py
+++ b/ods/tests/test-phase11-hermes-mount-refresh.py
@@ -23,6 +23,7 @@ class DockerFixture:
self.live = b"owner live config: preserve exactly\n"
self.other_identity = "b" * 64
self.keep_stale = False
+ self.keep_stale_alias = False
self.change_live = False
self.read_error = False
self.ids = None
@@ -72,6 +73,10 @@ class DockerFixture:
self.identity = "c" * 64
if not self.keep_stale:
self.mounted = {p: (self.root / relative).read_bytes() for p, relative in mounts.FILES.items()}
+ if not self.keep_stale_alias:
+ for mount in self.inspected_mounts:
+ if mount["Destination"] in mounts.FILES:
+ mount["Source"] = str(self.root / mounts.FILES[mount["Destination"]])
if self.change_live:
self.live = b"unexpected upstream config change"
return ""
@@ -172,6 +177,62 @@ class HermesMountTests(unittest.TestCase):
self.docker.refresh()
self.assertEqual(len(self.docker.mutations()), 1)
+ def file_proxy(self):
+ proxy_root = self.root / "desktop-proxies"
+ visible = proxy_root / "Ubuntu-24.04" / ("d" * 64)
+ visible.parent.mkdir(parents=True)
+ source = "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-24.04/" + "d" * 64
+ destination = next(iter(mounts.FILES))
+ expected = self.root / mounts.FILES[destination]
+ self.docker.inspected_mounts[0]["Source"] = source
+ return proxy_root, visible, expected
+
+ def test_current_desktop_file_alias_does_not_restart(self):
+ proxy_root, visible, expected = self.file_proxy()
+ os.link(expected, visible)
+ with patch.object(mounts, "DESKTOP_VISIBLE_ROOT", proxy_root):
+ self.assertEqual(self.docker.refresh(), "current")
+ self.assertFalse(self.docker.mutations())
+
+ def test_disappeared_desktop_alias_rebinds_even_when_running_bytes_match(self):
+ proxy_root, visible, expected = self.file_proxy()
+ os.link(expected, visible)
+ visible.unlink()
+ before = dict(self.docker.mounted)
+ with patch.object(mounts, "DESKTOP_VISIBLE_ROOT", proxy_root):
+ self.assertEqual(self.docker.refresh(), "refreshed")
+ self.assertEqual(len(self.docker.mutations()), 1)
+ self.assertEqual(self.docker.mounted, before)
+ self.assertEqual((self.root / "data/hermes/config.yaml").read_bytes(), self.docker.live)
+
+ def test_byte_identical_replacement_does_not_hide_stale_desktop_inode(self):
+ proxy_root, visible, expected = self.file_proxy()
+ os.link(expected, visible)
+ replacement = expected.with_suffix(".new")
+ replacement.write_bytes(expected.read_bytes())
+ os.replace(replacement, expected)
+ self.assertEqual(visible.read_bytes(), expected.read_bytes())
+ self.assertFalse(os.path.samefile(visible, expected))
+ with patch.object(mounts, "DESKTOP_VISIBLE_ROOT", proxy_root):
+ self.assertEqual(self.docker.refresh(), "refreshed")
+ self.assertEqual(len(self.docker.mutations()), 1)
+
+ def test_unrepaired_alias_fails_after_only_one_recreation(self):
+ proxy_root, _, _ = self.file_proxy()
+ self.docker.keep_stale_alias = True
+ with patch.object(mounts, "DESKTOP_VISIBLE_ROOT", proxy_root):
+ with self.assertRaisesRegex(mounts.Refused, "file aliases still differ"):
+ self.docker.refresh()
+ self.assertEqual(len(self.docker.mutations()), 1)
+
+ def test_foreign_owner_with_missing_alias_never_recreates(self):
+ proxy_root, _, _ = self.file_proxy()
+ self.docker.labels["com.docker.compose.project.working_dir"] = "/foreign/install"
+ with patch.object(mounts, "DESKTOP_VISIBLE_ROOT", proxy_root):
+ with self.assertRaisesRegex(mounts.Refused, "ownership"):
+ self.docker.refresh()
+ self.assertFalse(self.docker.mutations())
+
def test_postcheck_waits_for_healthy_startup_without_another_recreation(self):
self.docker.replace(next(iter(mounts.FILES)))
self.docker.startup_health = ["starting", "starting", "healthy"]