Skip to content

Guard Clear with an ownership marker and a path guard - #124

Merged
argonui merged 1 commit into
mainfrom
fix/clear-ownership-guard
Aug 4, 2026
Merged

Guard Clear with an ownership marker and a path guard#124
argonui merged 1 commit into
mainfrom
fix/clear-ownership-guard

Conversation

@argonui

@argonui argonui commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Fixes #96

Reverse mode calls DirOps.Clear(), which os.RemoveAlls the objects directory before rewriting it. If a user mistargets --moddir (say, at $HOME), that deletion could wipe out unrelated data, and the previous extension allowlist was only a weak proxy for "this tool owns this directory." This PR replaces that proxy with a real ownership signal plus a path guard: after recreating the directory, Clear drops a hidden .ttsmm-managed sentinel, and on subsequent runs it refuses to delete unless the directory is absent, empty, already carries the marker, or — for backward compatibility with trees written before the marker existed — passes the existing extension allowlist (which then earns a marker going forward). Independently, a pathGuard resolves the target to an absolute, cleaned path and refuses the filesystem root, the user's home directory, any ancestor of home, and suspiciously shallow single-segment paths, all with explicit errors. The marker is filtered out of ListFilesAndFolders so it never leaks into the pipeline as mod content, which as a side effect also clears the original .DS_Store/.gitkeep false positives since a tool-created directory no longer relies on the extension check. New unit tests in file/dirops_test.go cover refusal of unmarked foreign content, clearing of marked/empty/absent/legacy directories, and the path guard rejecting / and the home dir. go build, go vet, and go test ./... are all green.

Reverse mode calls DirOps.Clear(), which os.RemoveAll's the objects
directory. A mistargeted --moddir (e.g. $HOME) could destroy unrelated
data, and the extension allowlist was only a weak proxy for ownership.

Clear now drops a hidden .ttsmm-managed sentinel after recreating the
directory and refuses to delete unless the directory is absent, empty,
already carries the marker, or (for backward compatibility) passes the
existing extension allowlist. A pathGuard additionally refuses the
filesystem root, the home directory, any ancestor of home, and
suspiciously shallow paths. The marker is filtered out of
ListFilesAndFolders so it stays invisible to the rest of the pipeline.

Fixes #96

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@argonui
argonui force-pushed the fix/clear-ownership-guard branch from e3feaf8 to 7fd3062 Compare August 4, 2026 02:33
@argonui
argonui merged commit 949f493 into main Aug 4, 2026
@argonui
argonui deleted the fix/clear-ownership-guard branch August 4, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-clear safety check blocks reverse mode on any unrecognized file (.DS_Store, .gitkeep)

1 participant