fix: consolidate marker parsing + canonicalize mount paths#2
fix: consolidate marker parsing + canonicalize mount paths#2Dhravya wants to merge 6 commits intofeat/import-existing-on-mountfrom
Conversation
When mounting to a non-empty directory, detect existing files and prompt the user to import them into the container. Also fixes `smfs mount .` and `smfs unmount .` which previously failed because `.` was used as a literal container tag / couldn't walk up to find the .smfs marker. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…unt paths - Deduplicate .smfs marker parsing (was copy-pasted in marker.rs, unmount.rs, and grep.rs) into shared parse_marker/find_marker_from - Reject empty container_tag values in marker files - Canonicalize mount_path before writing to .smfs marker so downstream readers always get absolute paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| let canonical_mount = cfg | ||
| .mount_path | ||
| .canonicalize() | ||
| .unwrap_or_else(|_| cfg.mount_path.clone()); | ||
| std::fs::write( | ||
| &marker_path, | ||
| format!( | ||
| "container_tag={}\napi_url={}\nmount_path={}\n", | ||
| cfg.container_tag, | ||
| cfg.api_url, | ||
| cfg.mount_path.display(), | ||
| canonical_mount.display(), |
There was a problem hiding this comment.
Medium: canonicalizing the mount path in the marker breaks project-scoped credential lookups for non-canonical mounts.
The marker now stores mount_path as the canonicalized path, but the credential system (save_project, load_project, remove_project in smfs-core/src/config/credentials.rs) keys project credentials by whatever raw path string was passed at smfs mount time — it calls project_path(mount_path) which just encodes the path as-is without canonicalizing.
This means:
- A mount created with
--path ./mnt,--path ../mnt, or a symlinked path saves credentials under the original path key. - Later,
smfs grepreads the marker and gets back the canonicalized path, then callsload_projectwith that canonical path — a different key — so it misses the project credential and falls back to global creds or fails with "API key required". smfs logout --projectwill callremove_projectwith the canonical path, report success (becauseNotFoundis treated as success), but leave the original project credential file on disk.
Suggested fix: Apply the same normalization strategy everywhere. The simplest approach is to canonicalize in project_path() (or in a shared helper called by all of save_project/load_project/remove_project), so the credential key is always canonical regardless of how the path was originally passed. Alternatively, keep the raw path in the marker and remove the canonicalization added here.
26c9d85 to
ba83d50
Compare
Summary
.smfsmarker parsing — was copy-pasted inmarker.rs,unmount.rs, and inline ingrep.rs. Now there's oneparse_marker()andfind_marker_from()inmarker.rs.container_tagvalues in marker files (previouslycontainer_tag=\nwould silently produce an empty tag).mount_pathbefore writing to the.smfsmarker so downstream readers always get absolute paths regardless of how the mount was invoked.Test plan
.smfsmarker contains absolutemount_pathsmfs unmount .still works (uses sharedfind_marker_from)smfs grepfrom outside mount dir still resolves marker correctly.smfswithcontainer_tag=(empty value) — should fail gracefully🤖 Generated with Claude Code