Repository navigation
fs: require existing parents for OverlayFS creating operations - #863
Merged
Merged
Conversation
…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.
# Conflicts: # SPEC.md
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.
What changed
In overlay mode,
echo hi > /missing/dir/xused to succeed and quietly create/missing/dir.OverlayFS.OpenFilewithO_CREATEaccepted any missing path suffix (overlayMissingTail) and let the upperMemoryFScreate the parents. It now behaves like bash and likeMemoryFSafter #857: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.ENOTDIR.OpenFile(O_CREATE),Symlink,Link,RenameandMkfifomap theErrInvalidthat path resolution reports for a non-directory parent tosyscall.ENOTDIR. The shell renders it asNot 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.overlayMissingTailis removed; creating ops useoverlayMissingFinal.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).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/Mkfifocases.internal/runtime/fs_backends_test.go:TestOverlayRedirectIntoMissingDirectoryFailsWithoutCreatingParentsruns 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.Ran locally:
go test ./fs/... ./internal/runtime/...,make conformance-test CONFORMANCE_RUN='TestConformance/.*/oils/redirect', andmake lint(0 issues). Ininternal/builtins, only the ripgrep/diff oracle tests failed, because the Nix oracle env vars weren't set.