aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/transport/wire.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-14 11:17:38 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-14 11:17:38 +0200
commitdaec4bc6a2a9f9e038e5269586b06018ff327a27 (patch)
treec34c58aad624d594dbb1aa8a47f71ab38a5e3081 /packages/meshbay-node/src/meshbay_node/transport/wire.py
parent80ac882346b474bb7ea4e8c8afd4694bd13dd9dd (diff)
downloadmeshbay-daec4bc6a2a9f9e038e5269586b06018ff327a27.tar.gz
fix(node): index, serve and write files past Windows' MAX_PATH
With the system's default setting (LongPathsEnabled off) every call given a plain path of 260 characters or more refuses it, so a deep library was partly invisible: the walk could not list such a directory and its files never reached the members. The node now hands each call that touches a group's disk the extended form (paths.long_path), and keeps the plain path in the index, the hash cache and the log. A directory is listed under its long form and its entries named from the plain one (indexer.walk_files, wire._walk_dirs). Covered: the walk, stats and hashing, reconcile and the watcher, the folder list members see, serving over WebRTC and QUIC, deletion, uploads and their recovery, folder creation and removal, audio tags and the cover beside a track, photos, and a show's episode numbering. ffmpeg extends a long path itself and keeps the plain one. long_path now normalises before prefixing (the extended form skips the system's normalisation) and starts at 248 characters, where creating a directory is already refused. test_long_paths.py runs with the setting off: 15 of its 17 tests fail without the change. Checked by hand in the installed app with files at 312 to 380 characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/transport/wire.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/transport/wire.py35
1 files changed, 27 insertions, 8 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/transport/wire.py b/packages/meshbay-node/src/meshbay_node/transport/wire.py
index 77c5d62..75d27c1 100644
--- a/packages/meshbay-node/src/meshbay_node/transport/wire.py
+++ b/packages/meshbay-node/src/meshbay_node/transport/wire.py
@@ -32,6 +32,7 @@ from pathlib import Path
from meshbay_common import MNP_VERSION
from meshbay_common.groupbox import PURPOSE_INDEX, seal
+from meshbay_common.paths import long_path
from meshbay_common.protocol import MNP, index_entry_wire
from meshbay_node.roots import RootSet, off_disk
@@ -75,22 +76,40 @@ def _dir_roots(roots: RootSet) -> list[tuple[str, Path, bool]]:
def _walk_dirs(dir_roots: list[tuple[str, Path, bool]]) -> list[str]:
- """Blocking. Directories only: `os.walk` reads each one once and never
- stats a file, which `rglob("*")` and an `is_dir()` per entry did."""
+ """Blocking. Directories only: each is read once and no file is stat'ed,
+ which `rglob("*")` and an `is_dir()` per entry did. What `os.walk` did,
+ except that each directory is listed under its long form: `os.walk` skipped
+ whatever lay past Windows' MAX_PATH, without a word."""
out: list[str] = []
for name, path, available in dir_roots:
out.append(name)
if not available:
continue
- for top, subdirs, _files in os.walk(path):
- # Pruned in place: nothing under a hidden directory is listed either.
- subdirs[:] = [d for d in subdirs if not d.startswith(".")]
- rel = Path(top).relative_to(path)
- for d in subdirs:
- out.append(f"{name}/{(rel / d).as_posix()}")
+ pending = [path]
+ while pending:
+ top = pending.pop()
+ try:
+ with os.scandir(long_path(top)) as listing:
+ # Nothing under a hidden directory is listed either.
+ subdirs = [e for e in listing
+ if not e.name.startswith(".") and _is_dir(e)]
+ except OSError:
+ continue
+ rel = top.relative_to(path)
+ for entry in subdirs:
+ out.append(f"{name}/{(rel / entry.name).as_posix()}")
+ if not entry.is_symlink(): # listed, not entered, as os.walk did
+ pending.append(top / entry.name)
return sorted(out)[:MAX_DIRS]
+def _is_dir(entry: os.DirEntry) -> bool:
+ try:
+ return entry.is_dir()
+ except OSError:
+ return False
+
+
def index_sync_message(index, roots: RootSet | None, hidden=(),
dirs: list[str] | None = None) -> dict:
"""