Skip to content

fs: require existing parents for OverlayFS creating operations - #863

Merged
ewhauser merged 4 commits into
mainfrom
claude/agitated-zhukovsky-0df20e
Oct 19, 2026
Merged

ewhauser merged 4 commits into
mainfrom
claude/agitated-zhukovsky-0df20e

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Stacked on #857. This branch includes #857's commit (fs: require existing parents in MemoryFS…), because this change uses its createParentError and newMemoryWithImplicitParents helpers. Merge #857 first; after that, this PR's own change is the single top commit, and the branch may need a rebase if #857 is squash-merged.

What changed

In overlay mode, echo hi > /missing/dir/x used to succeed and quietly create /missing/dir. OverlayFS.OpenFile with O_CREATE accepted any missing path suffix (overlayMissingTail) and let the upper MemoryFS create the parents. It now behaves like bash and like MemoryFS after #857:

  • Missing parent → ENOENT. The parent must exist in the merged upper+lower view. Symlinked parents are followed the same way the rest of OverlayFS resolves paths. A parent hidden by a tombstone, a dangling symlinked parent, and a final dangling link whose target's parent is missing all fail without creating anything.
  • Non-directory parent → ENOTDIR. OpenFile (O_CREATE), Symlink, Link, Rename and Mkfifo map the ErrInvalid that path resolution reports for a non-directory parent to syscall.ENOTDIR. The shell renders it as Not a directory. Before fs: resolve overlay symlinks across layers #856 the other four creating ops could also create missing parents; after fs: resolve overlay symlinks across layers #856 they already rejected them, but they still returned EINVAL for a file parent.
  • overlayMissingTail is removed; creating ops use overlayMissingFinal.
  • The upper layer is unchanged and keeps newMemoryWithImplicitParents(), so creating a file under a directory that exists only in the lower layer still works (the parent is created in the upper layer on write).
$ echo hi > /w/missing/dir/x; echo rc=$?
/w/missing/dir/x: No such file or directory
rc=1
$ echo hi > /w/file.txt/x; echo rc=$?
/w/file.txt/x: Not a directory
rc=1

SPEC

SPEC.md: replaced the bullet saying the overlay's upper layer creates missing parents implicitly with the merged-view parent rule above.

Tests

  • fs/overlay_create_test.go: O_CREATE with truncate/append/exclusive flags; missing, tombstoned and dangling-symlink parents; file and file-symlink parents; a lower-only parent still works; Symlink/Link/Rename/Mkfifo cases.
  • internal/runtime/fs_backends_test.go: TestOverlayRedirectIntoMissingDirectoryFailsWithoutCreatingParents runs the redirect cases under an overlay factory. It checks exit code 1, the exact stderr, that no parent was created, and that writing into a lower-only directory still works.
  • Both new tests fail without the fix.

Ran locally: go test ./fs/... ./internal/runtime/..., make conformance-test CONFORMANCE_RUN='TestConformance/.*/oils/redirect', and make lint (0 issues). In internal/builtins, only the ripgrep/diff oracle tests failed, because the Nix oracle env vars weren't set.

…ubtree

MemoryFS creating operations (OpenFile with O_CREATE, Symlink, Link,
Rename) silently created missing parent directories, so
`echo hi > /nope/dir/x` succeeded where bash fails with ENOENT. They now
fail with ENOENT for a missing parent and ENOTDIR for a non-directory
parent, and the shell renders ENOTDIR as "Not a directory".

Rename of a directory into its own descendant deleted the subtree and
then dereferenced a nil parent; it now returns EINVAL like OverlayFS.
Link used the unresolved destination path and panicked when the parent
was a symlinked directory; it now uses the resolved path.

OverlayFS's private upper layer keeps implicit parent creation so
copy-up into lower-only directories still works.
OverlayFS.OpenFile with O_CREATE accepted any missing path suffix and
let the upper layer materialize the parents, so in overlay mode
`echo hi > /missing/dir/x` silently created /missing/dir. It now
requires the destination's parent to exist in the merged view, as
MemoryFS does: a missing parent (including one hidden by a tombstone or
behind a dangling symlink) fails with ENOENT, and a non-directory parent
fails with ENOTDIR.

Symlink, Link, Rename and Mkfifo already rejected missing parents; they
now also report ENOTDIR instead of EINVAL for a non-directory parent.
The upper layer keeps implicit parents so copy-up into directories that
exist only in the lower layer still works.
@ewhauser
ewhauser enabled auto-merge (squash) October 19, 2026 07:21
@ewhauser
ewhauser merged commit 7eb3199 into main Oct 19, 2026
16 checks passed
@ewhauser
ewhauser deleted the claude/agitated-zhukovsky-0df20e branch October 19, 2026 07:29
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.

1 participant