fs.globSync() uses process.cwd() when building the root exclude Dirent with withFileTypes
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 76/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- javascript
- Domínio
- operating-systems
Direção de pesquisa
Comece em lib/internal/fs/glob.js, em #addSubpattern(), comparando o branch síncrono de withFileTypes e exclude com o caminho assíncrono. Reproduza o problema com o script fornecido e, em seguida, verifique se o callback de exclude recebe um Dirent para o glob cwd em vez de process.cwd() e se o diretório é excluído.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Version
v25.8.2
Platform
Darwin arm64
Subsystem
fs
What steps will reproduce the bug?
const { mkdtempSync, mkdirSync, writeFileSync, globSync } = require('node:fs');
const { tmpdir } = require('node:os');
const { join } = require('node:path');
const { chdir, cwd } = require('node:process');
const base = mkdtempSync(join(tmpdir(), 'glob-root-'));
const ambient = join(base, 'ambient');
const root = join(base, 'root');
mkdirSync(ambient, { recursive: true });
mkdirSync(join(root, 'a'), { recursive: true });
writeFileSync(join(ambient, 'a'), 'shadow-file');
writeFileSync(join(root, 'a', 'real.txt'), 'real');
chdir(ambient);
const seen = [];
const result = globSync('a/**', {
cwd: root,
withFileTypes: true,
exclude: (dirent) => {
seen.push({
name: dirent.name,
parentPath: dirent.parentPath,
isDirectory: dirent.isDirectory(),
isFile: dirent.isFile(),
});
return dirent.isDirectory();
},
});
console.log(JSON.stringify({
processCwd: cwd(),
globCwd: root,
seen,
result: result.map((dirent) => ({
name: dirent.name,
parentPath: dirent.parentPath,
isDirectory: dirent.isDirectory(),
isFile: dirent.isFile(),
})),
}, null, 2));
How often does it reproduce? Is there a required condition?
It reproduces consistently in globSync() when all of the following are true:
withFileTypes: truecwd !== process.cwd()- the pattern goes through the root-entry
#addSubpattern()path (for examplea/**)
If the ambient process.cwd() also contains the same relative path, the callback receives a Dirent for the ambient path instead of the glob cwd path. If the ambient cwd does not contain that path, the root entry can skip the callback entirely because statSync(path) returns null.
The async glob path does not seem affected.
What is the expected behavior? Why is that the expected behavior?
The exclude callback should receive a Dirent describing the candidate entry under options.cwd.
For the repro above, the callback should receive a directory dirent for <globCwd>/a, so dirent.isDirectory() should be true and the result should be an empty array because the callback returns true for directories.
What do you see instead?
The callback receives a Dirent for the ambient process.cwd() path instead:
{
"processCwd": "/tmp/.../ambient",
"globCwd": "/tmp/.../root",
"seen": [
{
"name": "a",
"parentPath": ".",
"isDirectory": false,
"isFile": true
},
{
"name": "real.txt",
"parentPath": "/tmp/.../root/a",
"isDirectory": false,
"isFile": true
}
],
"result": [
{
"name": "a",
"parentPath": "/tmp/.../root",
"isDirectory": true,
"isFile": false
},
{
"name": "real.txt",
"parentPath": "/tmp/.../root/a",
"isDirectory": false,
"isFile": true
}
]
}
So the root a entry is not excluded even though the callback logic is meant to exclude directories.
Additional information
This looks like a sync-only regression in the root-path exclude handling added for #56260 / #57420.
In lib/internal/fs/glob.js, #addSubpattern() computes const fullpath = resolve(this.#root, path), but in the withFileTypes + exclude branch it does:
const stat = this.#cache.statSync(path);
That appears to stat a path relative to process.cwd() instead of options.cwd. The async path already uses await this.#cache.stat(fullpath).
- Linguagem predominante
- JavaScript
- Estrelas
- 122k
- Forks
- 37.4k
- Merge médio
- 4d 3h
- PRs com merge (30d)
- 279
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de nodejs/node
-
doc
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
build
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
-
feature request
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Todas as issues de nodejs/node
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
Theme loads third-party resources on every page (jsdelivr web font, cdnjs Font Awesome) – GDPR Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
docToolchain/docToolchain#1705 ·
-
Timezone select lists one option per character; duplicate "Failed" reason; shared tracker popover id Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
nightscout/nocturne#1414 ·
-
bug v2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
modelcontextprotocol/inspector#2458 · 1 comentário ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
carbon-design-system/ibm-products#9907 ·