fix(memfs): Fix enumeration and RemoveAll for prefix-named siblings#17
Merged
Conversation
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
In
memfs, a directory's entries could vanish from enumeration, andRemoveAllcould delete unrelated directories, when a sibling shares the target's name as a string prefix (e.g.dir0-tmpalongsidedir0). All three bugs stem from confusing a string prefix with a path-segment prefix inmemfs/store.go.Open/Stat/ReadFileof an exact path were unaffected — only enumeration and bulk removal.prefixKeys(backsReadDir, and thereforefs.WalkDir): broke the scan at the first key not underdir/. A sibling likedir0-tmpsorts betweendir0anddir0/...('-'0x2d <'/'0x2f), so the real children were never reached andReadDirreturned zero entries. Siblings are now skipped (continue); the scan stops only when the shared string prefix ends.prefixGlobKeys(backsGlob): same shape, same fix.removeAll(backsRemoveAll): deleted every key with the string prefix, soRemoveAll("dir0")also removeddir0-tmp,dir0_bak, etc. It now deletes only the directory itself and its true children (key == prefix || HasPrefix(key, prefix+"/")).Surfaced via a downstream backend layered on
wfsthat usesfs.WalkDir/ReadDir: sibling index directories made a base directory invisible to enumeration undermem://, whileosfsands3behaved correctly (they walk real directories / list a flat keyspace without the contiguity shortcut).Test plan
go test -race ./...staticcheck ./memfs/gosec ./memfs/