Repository navigation
vfs: enforce trailing separators on mounted paths - #67972
Open
dcavalcante wants to merge 1 commit into
Open
dcavalcante wants to merge 1 commit into
dcavalcante wants to merge 1 commit into
Conversation
A path with a trailing separator must name a directory, but resolving a
mounted path drops the separator, so VFS operations acted on the file:
fs.readFileSync('<mount>/file/') returned its contents,
fs.writeFileSync('<mount>/file/') overwrote it, and fs.unlinkSync() and
fs.rmSync() deleted it, where a real file system fails with ENOTDIR or
EISDIR.
Enforce the separator where paths are resolved, the way each operation
enforces it on a POSIX file system: lookups follow links and require a
directory; lstat(), readlink() and the l*() functions act on the
directory a final link names; unlink(), rmdir() and the source of
rename() require the entry itself to be a directory; creating a file or
a link there fails. rm() refuses a link to a directory rather than
following it into its target.
Paths given to an unmounted file system now lose a trailing separator
as mounted ones already did, and the callback functions of a
VirtualFileSystem report errors from resolving the path through the
callback instead of throwing. As for a real path, fs.statSync() with
throwIfNoEntry: false returns undefined on ENOTDIR as well as ENOENT.
Signed-off-by: Daniel Cavalcante <dcavalcante@gmail.com>
Assisted-by: Claude Opus 5.5
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67972 +/- ##
==========================================
- Coverage 90.58% 90.56% -0.03%
==========================================
Files 802 802
Lines 286735 287123 +388
Branches 55396 55490 +94
==========================================
+ Hits 259741 260034 +293
- Misses 17091 17176 +85
- Partials 9903 9913 +10
🚀 New features to boost your workflow:
|
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.
A path with a trailing separator must name a directory. The VFS dropped the separator while resolving mounted paths, so operations acted on the file instead of failing as they do on a real file system:
The separator is now enforced in one place,
VirtualFileSystem#toProviderPath, as each operation enforces it on POSIX:lstat(),readlink()and the otherl*()functions act on the directory a final link names;unlink(),rmdir()and the source ofrename()require the entry itself to be a directory;On Linux, I compared the VFS with real
fsfor 27 operations, each on a file, a directory, a missing path, and links to a file, a directory and nothing, using both the sync and promise APIs. Before this change, 71 results differed with a trailing separator; now none do. Paths without a trailing separator behave exactly as before.Notes:
rm('link-to-dir/', { recursive: true })throwsENOTDIRand removes nothing. Realfscurrently empties the link's target directory first (fs: rmSync() deletes a symlinked directory's contents then throws ENOTDIR when the path has a trailing slash #67186), and the VFS deliberately doesn't follow that.realpath()still ignores the separator. The JS and native implementations differ there, and they share one VFS hook.fs.statSync()withthrowIfNoEntry: falsenow returnsundefinedonENOTDIRas well asENOENT.Refs: #67186
Assisted-by: Claude Opus 5.5
cc @mcollina