diff options
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: """ |