aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/ops/roots.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-08 01:11:38 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-08 01:11:38 +0200
commited0c680790950354f15fb5835e1d7b213efa1bf8 (patch)
tree59af376652005a0b02c95945c1df6044882a94e5 /packages/meshbay-node/src/meshbay_node/ops/roots.py
parent4c8e4fb8b8fcd3f78bf4e3e736a058c351aac973 (diff)
downloadmeshbay-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/ops/roots.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops/roots.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/ops/roots.py b/packages/meshbay-node/src/meshbay_node/ops/roots.py
index b976e8f..c272978 100644
--- a/packages/meshbay-node/src/meshbay_node/ops/roots.py
+++ b/packages/meshbay-node/src/meshbay_node/ops/roots.py
@@ -14,7 +14,7 @@ from meshbay_node.ops.node_toml import (
_update_root_field,
toml_string,
)
-from meshbay_node.roots import RootError, RootSet, off_disk
+from meshbay_node.roots import RootError, RootSet, distinct_name, off_disk
log = logging.getLogger("meshbay_node.ops")
@@ -36,12 +36,21 @@ async def add_root(state: dict, group_id: str, path: str, *,
raise OpError("Group not configured on this node", status=404)
specs = [asdict(r) for r in cfg.roots]
- specs.append({"path": path, "name": name, "kind": kind,
- "writable": writable, "removable": removable})
try:
+ # Every caller sends the folder's basename when nobody typed a name, so
+ # that is the case that gets a distinct one. A name somebody chose is
+ # still refused on a clash.
+ target = Path(path).expanduser().resolve()
+ if name.strip() in ("", target.name):
+ taken = {r.folded for r in RootSet.build(specs).roots}
+ name = distinct_name(target, taken)
+ specs.append({"path": path, "name": name, "kind": kind,
+ "writable": writable, "removable": removable})
built = RootSet.build(specs)
except RootError as e:
raise OpError(str(e)) from e
+ except OSError as e:
+ raise OpError(f"{path}: {e}") from e
added = built.roots[-1]