Skip to content

vfs: reject rename onto a non-empty directory - #65373

Open
dibenkobit wants to merge 1 commit into
nodejs:mainfrom
dibenkobit:vfs-rename-enotempty
Open

vfs: reject rename onto a non-empty directory#65373
dibenkobit wants to merge 1 commit into
nodejs:mainfrom
dibenkobit:vfs-rename-enotempty

Conversation

@dibenkobit

@dibenkobit dibenkobit commented Aug 18, 2026

Copy link
Copy Markdown

POSIX requires the destination of a directory rename to be an empty directory. fs.renameSync() reports ENOTEMPTY because the OS enforces it, and RealFSProvider inherits that by delegating to the real filesystem. MemoryProvider has no OS underneath, so it implements these rules itself — it already covers EISDIR, ENOTDIR and EINVAL, but not this one: it renamed over a non-empty directory and silently discarded its contents.

Assisted-By: Claude Code (Claude Opus 5)

MemoryProvider.renameSync() rejected directory/non-directory
mismatches but never checked whether an existing directory
destination was empty, so renaming a directory onto a non-empty one
silently discarded the destination's contents.

POSIX rename(2) requires the destination directory to be empty, and
RealFSProvider already reports ENOTEMPTY, so the two providers Node
ships disagreed with each other.

Signed-off-by: Nikita Snetkov <lukyanish@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants