diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-04 02:20:48 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-04 02:20:48 +0200 |
| commit | 7a4b905ddb64bdc92b7f9acf2ccde9bd84d7a6f3 (patch) | |
| tree | cc9c7025c2b2d7fc31571b3589ecabcb6f63d8c2 /packages/meshbay-node/src/meshbay_node/daemon.py | |
| parent | 5022f2be149e40ac5bdd5fc362e926f3edcf44f0 (diff) | |
| download | meshbay-7a4b905ddb64bdc92b7f9acf2ccde9bd84d7a6f3.tar.gz | |
fix(node): pin utf-8 (and LF) on every text file the node reads or writes
node.toml, the keystore envelope, the unlock key, the loopback UI token,
pairing/invite code files and the denylist were all read and written with
the platform default encoding and newline translation. On Windows that is
cp1252 + CRLF: a node.toml or keystore holding any non-ASCII byte failed to
load, and ops.py's line-based node.toml editor round-tripped CRLF in and
LF out.
Every read is now `encoding="utf-8"`; every write is `encoding="utf-8",
newline="\n"` so the files stay LF whatever the OS. No-op where the locale
was already UTF-8.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/daemon.py')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/daemon.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/daemon.py b/packages/meshbay-node/src/meshbay_node/daemon.py index d616b0c..72f7fa4 100644 --- a/packages/meshbay-node/src/meshbay_node/daemon.py +++ b/packages/meshbay-node/src/meshbay_node/daemon.py @@ -219,7 +219,7 @@ class NodeDaemon: # should ever copy a token out of a log or a terminal. self._config.data_dir.mkdir(parents=True, exist_ok=True) self._ui_token_file = self._config.data_dir / "ui-token" - self._ui_token_file.write_text(ui_token) + self._ui_token_file.write_text(ui_token, encoding="utf-8", newline="\n") chmod_private(self._ui_token_file) from meshbay_node.ui import create_ui_app ui_app = create_ui_app(self._state) @@ -1526,7 +1526,7 @@ def _daemon_api(cfg: Config, path: str, method: str = "GET", sep = "&" if "?" in path else "?" url = (f"http://127.0.0.1:{cfg.node.ui_port}{path}" - f"{sep}t={token_file.read_text().strip()}") + f"{sep}t={token_file.read_text(encoding="utf-8").strip()}") try: data = _json.dumps(body).encode() if body is not None else None req = urllib.request.Request( @@ -1708,7 +1708,7 @@ def main() -> None: sys.exit(1) if cfg_path.exists(): - existing = cfg_path.read_text() + existing = cfg_path.read_text(encoding="utf-8") import re as _re m = _re.search(r'username\s*=\s*"([^"]*)"', existing) existing_user = m.group(1) if m else "" @@ -1721,7 +1721,7 @@ def main() -> None: r'(username\s*=\s*)"[^"]*"', rf'\1"{username}"', existing) updated = _re.sub( r'(url\s*=\s*)"[^"]*"', rf'\1"{hub_url}"', updated, count=1) - cfg_path.write_text(updated) + cfg_path.write_text(updated, encoding="utf-8", newline="\n") print(f"Config updated: username={username}, hub={hub_url}") else: print(f"Config already exists: {cfg_path}") @@ -1741,7 +1741,7 @@ def main() -> None: f'unlock_file = "{unlock_file}"', "", ] - cfg_path.write_text("\n".join(toml_lines) + "\n") + cfg_path.write_text("\n".join(toml_lines) + "\n", encoding="utf-8", newline="\n") chmod_private(cfg_path) print(f"Config written to {cfg_path}") @@ -1749,7 +1749,7 @@ def main() -> None: if not unlock_file.exists(): import secrets key = secrets.token_urlsafe(32) - unlock_file.write_text(key + "\n") + unlock_file.write_text(key + "\n", encoding="utf-8", newline="\n") chmod_private(unlock_file) print(f"Unlock key created: {unlock_file}") @@ -1815,7 +1815,7 @@ def main() -> None: if token_file.exists(): try: cfg = Config(config_dir_ / "node.toml") - tok = token_file.read_text().strip() + tok = token_file.read_text(encoding="utf-8").strip() url = (f"http://127.0.0.1:{cfg.node.ui_port}" f"/api/unlink?t={tok}") req = urllib.request.Request(url, method="DELETE") @@ -1864,7 +1864,7 @@ def main() -> None: if token_file.exists(): try: url = (f"http://127.0.0.1:{cfg.node.ui_port}" - f"/api/status?t={token_file.read_text().strip()}") + f"/api/status?t={token_file.read_text(encoding="utf-8").strip()}") with urllib.request.urlopen(url, timeout=3) as r: live = _json.loads(r.read()) except Exception: |