fix: MemMapFs.OpenFile checks parent dir exists before creating file#572
Open
veeceey wants to merge 1 commit intospf13:masterfrom
Open
fix: MemMapFs.OpenFile checks parent dir exists before creating file#572veeceey wants to merge 1 commit intospf13:masterfrom
veeceey wants to merge 1 commit intospf13:masterfrom
Conversation
… file MemMapFs.OpenFile with O_CREATE was silently creating parent directories that don't exist, diverging from os.OpenFile semantics. This caused WriteFile to succeed when writing to non-existent directories in MemMapFs, while OsFs correctly returned an error. Now OpenFile verifies the parent directory exists before creating a new file, returning os.ErrNotExist if it doesn't. This matches the behavior of the real filesystem. Fixes spf13#270
Author
Test ResultsFull test suite passes: Verified the fix with the new test Also confirmed manually that |
Author
|
gentle ping when you have a moment |
6 tasks
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.
Fixes #270
MemMapFs.OpenFilewithO_CREATEwas silently creating parent directories that don't exist. This meantWriteFilewould happily write to non-existent paths in MemMapFs whileOsFswould correctly return an error -- inconsistent behavior.The fix adds a parent directory existence check in
OpenFilebefore callingCreate. If the parent doesn't exist, it returnsos.ErrNotExist, matchingos.OpenFilesemantics.Updated existing tests that relied on the implicit directory creation to explicitly create directories first (which is what you'd need to do on a real filesystem anyway). Added a dedicated test covering the bug.