nodejs / nodejs/node

Discrepancy between `fs.rmSync` and `fs/promises.rm` behavior with `.` and `..` in paths

Abierto
#61,958 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

confirmed-bug fs
Lenguaje dominante
JavaScript
Estrellas
122k
Forks
37.3k
Merge medio
4 d 2 h
PR fusionados (30 d)
283

Descripción

Version

v25.6.1

Platform
Darwin moxy.lan 25.3.0 Darwin Kernel Version 25.3.0: Wed Jan 28 20:47:03 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6031 arm64
Subsystem

lib/internal/fs/rimraf.js

What steps will reproduce the bug?

Create a nested folder:

mkdir -p a/b/c/d

Attempt to delete with this weirdly constructed path:

Welcome to Node.js v25.6.1.
Type ".help" for more information.
> await require('fs/promises').rm('a/b/../.', { recursive: true, force: true })
Uncaught [Error: EINVAL: invalid argument, rmdir 'a/b/../.'] {
  errno: -22,
  code: 'EINVAL',
  syscall: 'rmdir',
  path: 'a/b/../.'
}

Verify that nothing was removed:

$ tree
./
└── a/
    └── b/
        └── c/
            └── d/

Attempt to delete synchronously:

> require('fs').rmSync('a/b/../.', { recursive: true, force: true })
undefined

It was (mostly?) removed:

$ tree
./
└── a/

The weird thing is that a/b/../. should resolve to just a, so it's weird that it only deletes up to b. It's almost as if the rmSync method is coalescing /../. into just /.

Also, if the . is not the last item, then it seems to be fine? a/b/.././b deletes the b folder, and a/b/.. deletes just b, but not a.

At least, it seems like the sync and asynchronous methods should either both fail, or both succeed, with the same error.

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

every time, see repro steps above

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

sync and asynchronous rm methods should fail and succeed in the same way on the same input.

What do you see instead?

Some cases where rmSync succeeds, and fs/promises.rm fails.

Additional information

I have a fix that I could land in the upstream rimraf library, and I'd of course be happy to send a PR to node to bring it back into alignment, since there have also been some improvements in performance and Windows reliability.

But it'd be good to know what the intended behavior is, so that the errors can be made consistent with Node's intended design first.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con lib/internal/fs/rimraf.js y ejecuta la reproducción reportada de a/b/../. tanto para fs/promises.rm como para fs.rmSync. Compara cómo se gestiona cada ruta y determina cuál es el comportamiento coherente previsto antes de revisar las pruebas del sistema de archivos circundantes. Se considera terminado cuando las dos APIs coinciden para estos casos de rutas con puntos y la cobertura de regresión protege ese comportamiento.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, nodejs
Área
backend, operating-systems
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.