Skip to content

fs.cp of a directory fails on VFS (regression from the fast path) #67892

Backlog

Description

@hamzakargin

Version

main @ 1611823

Platform

macOS arm64

Subsystem

fs / node:vfs

What steps will reproduce the bug?

// repro.mjs
import vfs from 'node:vfs';
import fs from 'node:fs';

const mnt = vfs.create().mount();
fs.mkdirSync(`${mnt}/src`);
fs.writeFileSync(`${mnt}/src/a.txt`, 'hi');

// works
await fs.promises.cp(`${mnt}/src`, `${mnt}/dst2`, {
  recursive: true,
  filter: () => true,
});

// fails
await fs.promises.cp(`${mnt}/src`, `${mnt}/dst`, { recursive: true });

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

Copying a directory on a VFS mount works.

What do you see instead?

ENOTDIR: not a directory, mkdir '/dev/null/vfs/1/dst'

Additional information

The fast path from #65488 (29667e0) is at lib/internal/fs/cp/cp.js:319. It sends the whole folder copy to native code. Native code does not know about VFS, so /dev/null/vfs/1/... looks like a real path and fails.

The copy with a filter works. A filter does not change what gets copied; it only skips the fast path and runs the old JS walk. So the fast path is the broken part.

Related: fs.cpSync also fails on VFS, but that is not a regression. It probably needs a separate issue.

I have a fix ready and will open a PR for it.

cc @codebytere

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions