Files
pyxis/patch_littlefs_paths.py
torlando-agent[bot] 70d4aa6be9 feat: graft pyxis onto upstream microReticulum 0.4.1
Repins microReticulum + microLXMF onto the upstream-0.4.1 graft and adapts
pyxis to the new src/microReticulum/ layout and 0.4.x APIs. The far-diverged
0.3.0 fork's Resource/Transport/Identity work is subsumed by upstream's
reimplementation; only the still-needed fixes ride on the pinned branches
(PKCS7/HMAC/X25519 crypto -- proven byte-identical to python RNS 1.3.1 --
Packet link-proof callback, Identity short-sig guard, and the bz2 layer +
decompress-on-receive in Resource::assemble()).

Consumer-side changes:
- platformio.ini: pin microReticulum @2f21fee (pyxis-fixes-on-0.4.1) and
  microLXMF @33760d0 (chore/microreticulum-0.4.1-layout); bump microStore
  ceea8f5 -> c5fb69d (0.4.x requires the new BasicFileStore::init API);
  -std=gnu++11 -> gnu++17 (upstream requires C++17).
- Namespace all microReticulum includes (angle + quote) to <microReticulum/...>
  for the relocated layout; shim-local Utilities/Stream.h|Print.h preserved.
- Interface::send_outgoing now returns bool: update TCP/BLE/SX1262/Auto
  overrides with correct success/failure returns.
- SDArchiveFileSystem::init(bool reformatOnFail=true) to match new microStore.
- Static Transport::get_path_table() -> path_table(); instance getter unchanged.
- Remove duplicate shim Cryptography/BZ2 (microReticulum provides it now; keep
  lib/libbz2 as the ESP32 bzlib provider).
- patch_littlefs_paths.py: normalize microStore's LittleFS adapter paths to a
  leading "/" -- ESP32 Arduino LittleFS rejects "./"-prefixed paths, which
  silently broke the path store (no peer paths learned, all messaging blocked).

Validated on T-Deck Plus: builds (RAM 27.5% / Flash 77.7%), boots stable
(no WDT/panic), and a full on-device LXMF e2e (DIRECT + OPPORTUNISTIC +
bz2-compressed-Resource receive) passes 5/5.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWZuYkHBRqNb6BZHV8sTG5
2026-06-19 15:49:44 -04:00

96 lines
4.1 KiB
Python

"""
PlatformIO pre-build script: patches the libdeps copy of microStore's
LittleFSFileSystem adapter so every file path is normalized to a leading "/".
Why: ESP32's Arduino LittleFS/VFS rejects any path that does not start with
"/" (it logs nothing and returns an invalid File). But microStore's own
adapter init-test uses "./__init_test__" and microReticulum's Transport path
store uses "./path_store" -> "./path_store_0.dat". Both are relative ("./")
paths that work on native POSIX but fail on-device: the LittleFS check
"fails" and reformats every boot, and `open_segment` can never open
"./path_store_0.dat", so the path table never persists and pyxis never learns
any peer's path ("Failed to add destination ... to path table!"). That blocks
all LXMF messaging.
This is a platform-correctness concern that belongs in the ESP32 adapter, so
we normalize "./x" / "x" -> "/x" at each LittleFS.* call site there. Native
builds (PosixFileSystem) are unaffected — they don't use this adapter.
Idempotent: detects the already-patched state via the _pyxis_norm_path marker.
TODO(upstream): attermann/microStore's LittleFSFileSystem adapter should
normalize paths to a leading "/" itself (file an issue / PR on the fork).
"""
Import("env") # noqa: F821
import os
import sys
ADAPTER_H = os.path.join(
env.get("PROJECT_DIR", "."), # noqa: F821
".pio", "libdeps", env.get("PIOENV", "tdeck"), # noqa: F821
"microStore", "include", "microStore", "Adapters", "LittleFSFileSystem.h",
)
MARKER = "_pyxis_norm_path"
HELPER = """namespace microStore { namespace Adapters {
// patched-by-pyxis: ESP32 Arduino LittleFS requires a leading "/". microStore
// and microReticulum use "./"-prefixed paths that work on POSIX but fail here.
static inline std::string _pyxis_norm_path(const char* p) {
\tstd::string s(p ? p : "");
\tif (s.rfind("./", 0) == 0) s.erase(0, 2);
\tif (s.empty() || s.front() != '/') s.insert(s.begin(), '/');
\treturn s;
}
"""
# (old, new) — order matters so the more-specific open() forms are rewritten
# before the bare open(path) form (which is a non-overlapping distinct string).
REPLACEMENTS = [
("LittleFS.open(path, pmode)", "LittleFS.open(_pyxis_norm_path(path).c_str(), pmode)"),
("LittleFS.open(path, FILE_READ)", "LittleFS.open(_pyxis_norm_path(path).c_str(), FILE_READ)"),
("LittleFS.open(path)", "LittleFS.open(_pyxis_norm_path(path).c_str())"),
("LittleFS.exists(path)", "LittleFS.exists(_pyxis_norm_path(path).c_str())"),
("LittleFS.remove(path)", "LittleFS.remove(_pyxis_norm_path(path).c_str())"),
("LittleFS.rename(from_path, to_path)","LittleFS.rename(_pyxis_norm_path(from_path).c_str(), _pyxis_norm_path(to_path).c_str())"),
("LittleFS.mkdir(path)", "LittleFS.mkdir(_pyxis_norm_path(path).c_str())"),
("LittleFS.rmdir(path)", "LittleFS.rmdir(_pyxis_norm_path(path).c_str())"),
]
def main():
if not os.path.exists(ADAPTER_H):
# libdeps not fetched yet on a clean tree — PIO runs this again post-fetch.
print(f"[patch_littlefs_paths] {ADAPTER_H} not present yet; skipping")
return
with open(ADAPTER_H) as f:
src = f.read()
if MARKER in src:
print("[patch_littlefs_paths] already patched; skipping")
return
if "#include <string>" not in src:
src = src.replace("#include <LittleFS.h>",
"#include <LittleFS.h>\n#include <string>", 1)
# Inject the helper by expanding the namespace-open line.
anchor = "namespace microStore { namespace Adapters {"
if anchor not in src:
print(f"[patch_littlefs_paths] FATAL: namespace anchor not found in {ADAPTER_H}")
sys.exit(1)
src = src.replace(anchor, HELPER, 1)
for old, new in REPLACEMENTS:
if old not in src:
print(f"[patch_littlefs_paths] FATAL: expected call site not found: {old!r}")
sys.exit(1)
src = src.replace(old, new)
with open(ADAPTER_H, "w") as f:
f.write(src)
print("[patch_littlefs_paths] normalized LittleFS adapter paths to leading '/'")
main()