MemMapFs: Mkdir now errors when the parent directory doesn't exist#599
Open
c-tonneslan wants to merge 1 commit into
Open
MemMapFs: Mkdir now errors when the parent directory doesn't exist#599c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
Previously, MemMapFs.Mkdir would silently create any missing parent directories through registerWithParent, so it acted like MkdirAll. This diverges from os.Mkdir, which returns ENOENT if the parent isn't there. It also masked bugs in callers that relied on the error to know the path was invalid. Fix: Mkdir now checks that the parent directory exists before creating the new one. If the parent is missing it returns os.ErrNotExist, matching os.Mkdir behavior. MkdirAll is updated to explicitly recurse over missing parents first, rather than relying on Mkdir's now-removed implicit creation. TempDir is updated to ensure the base dir exists before calling Mkdir, since in-memory filesystems start empty. Two tests that called Mkdir with deep paths expecting implicit parent creation are fixed to use MkdirAll or pre-create the parent. Fixes spf13#149
c-tonneslan
added a commit
to c-tonneslan/portfolio
that referenced
this pull request
May 12, 2026
c-tonneslan
added a commit
to c-tonneslan/c-tonneslan
that referenced
this pull request
May 12, 2026
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 #149.
MemMapFs.Mkdirwas silently creating any missing parent directories viaregisterWithParent, so it behaved likeMkdirAll. This diverges fromos.Mkdir, which returnsENOENTwhen the parent doesn't exist.The practical problem: if you have a typo in a path,
Mkdirwould happily create the whole tree rather than failing, masking the bug entirely. That's the kind of thing that makes test suites usingMemMapFspass while production code (usingOsFs) fails.Changes:
Mkdirchecks that the parent directory exists before creating the new one. If the parent is missing it returnsos.ErrNotExist.MkdirAllis rewritten to explicitly recurse over missing parents, since it can no longer rely onMkdir's old implicit creation.TempDirnow callsMkdirAllon the base dir before callingMkdir, since in-memory filesystems start empty.Mkdirwith deep paths expecting the old behavior are updated.Before:
After: