diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-08 01:11:38 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-08 01:11:38 +0200 |
| commit | ed0c680790950354f15fb5835e1d7b213efa1bf8 (patch) | |
| tree | 59af376652005a0b02c95945c1df6044882a94e5 /packages/meshbay-node/src/meshbay_node/roots.py | |
| parent | 4c8e4fb8b8fcd3f78bf4e3e736a058c351aac973 (diff) | |
| download | meshbay-ed0c680790950354f15fb5835e1d7b213efa1bf8.tar.gz | |
fix(node): name a root after its drive when its basename is taken
Two drives with a folder of the same name made the second add fail,
and no screen could supply another name. add_root now names it
"Name (H)" or "Name (parent)"; a name the operator typed is still
refused on a clash.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/roots.py')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/roots.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/roots.py b/packages/meshbay-node/src/meshbay_node/roots.py index 2b48292..7dded1f 100644 --- a/packages/meshbay-node/src/meshbay_node/roots.py +++ b/packages/meshbay-node/src/meshbay_node/roots.py @@ -211,6 +211,27 @@ def derive_name(path: Path) -> str: return name +def distinct_name(path: Path, taken: set[str]) -> str: + """ + `derive_name(path)`, or, when a root in `taken` (folded names) already has + it, that name followed by where the directory is: `Archives (H)` for + `H:\\Archives` beside `G:\\Archives`, `Films (b)` for `/mnt/b/Films`. + + The same folder name on two drives is the ordinary case, and the interface + has no field to type a name into, so refusing it left no way forward. + """ + base = derive_name(path) + candidates = [base] + where = path.parent.name or path.drive.rstrip(":") + if where: + candidates.append(f"{base} ({where})") + candidates += [f"{base} ({n})" for n in range(2, 100)] + for name in candidates: + if fold(name) not in taken and not portable_name_problem(name): + return name + return base + + @dataclass class RootSet: """ |