Skip to content

fs.globSync fails when fs.glob does not #61257

@valler

Description

@valler

Version

25

Platform

Darwin

Subsystem

fs

What steps will reproduce the bug?

fs.writeFileSync("foo", "");
fs.globSync("foo/bar");

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

always

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

Expected:

fs.writeFileSync("foo", "");
fs.globSync("foo/bar").length == 0;

Because:

fs.writeFileSync("foo", "");
await new Promise(r => fs.glob("foo/bar", e => e ?? r());
fs.unlinkSync("foo");
fs.globSync("foo/bar").length == 0;

What do you see instead?

Uncaught:
Error: ENOTDIR: not a directory, lstat '/tmp/foo/bar'
    at lstatSync (node:fs:1677:25)
    at getDirentSync (node:internal/fs/glob:68:16)
    at Cache.statSync (node:internal/fs/glob:134:17)
    at #addSubpatterns (node:internal/fs/glob:395:32)
    at Glob.globSync (node:internal/fs/glob:312:29)
    at Object.globSync (node:fs:3200:37) {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'lstat',
  path: '/tmp/foo/bar'
}

Additional information

Edit: reduced code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions