fix(init): refuse to index the filesystem root or $HOME - #337
Merged
Conversation
Owner
|
@vitaliyslion can you please check the failed test? UPD: Looks like a flaky test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gortex inithad no guard against being pointed at a dangerous root — running it against$HOME(or/) walks the entire tree by default, since--skillsdefaults to on.gortex trackalready refused these paths viaindexer.UnsafeIndexRootReason;initnever called it. This wires the same guard intoinit, checked before the wizard, any indexing, or any file writes.Changes
cmd/gortex/init.go:runInitnow resolvesabsRootimmediately after parsing the[path]arg and, unless--forceis set, callsindexer.UnsafeIndexRootReason(absRoot)before doing anything else (wizard, indexing, or writes). Refuses with the reason plus; pass --force to init it anywaywhen the target is the filesystem root, a Windows drive root, or exactly$HOME. Removed the now-redundant laterfilepath.Abs(root)recomputation. Updated the--forceflag help text to mention the new bypass.cmd/gortex/init_integration_test.go: addedTestInitRefusesHomeDirectory(asserts the refusal, its error message, and that no.gortex/marker is written) andTestInitForceBypassesHomeDirectoryGuard(asserts--forcestill proceeds).Testing
TestInitRefusesHomeDirectory,TestInitForceBypassesHomeDirectoryGuard)go test ./cmd/gortex/... -run TestInit— all init/init-wizard tests passgo build ./cmd/gortex/...gortex init "$HOME" --yesrefuses with the home-directory message;gortex init "$HOME" --yes --forceproceedsgo test -race ./...not run (scoped to the touched package; happy to run the full suite before merge if wanted)Checklist
unsafeRootBlocked/pass force to track it anywayconvention already used bygortex track)Meta["methods"]for interfaces (not applicable)EdgeMemberOfedges to their containing type (not applicable)