nodejs / nodejs/node

fs.cpSync / fs.cp / fs.promises.cp fails when src/dest args are Buffer

Offen
#58,634 12 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

confirmed-bug fs
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

Version

All

Platform
All
Subsystem

fs

What steps will reproduce the bug?
const { cpSync, cp, promises } = require('node:fs');

cpSync(Buffer.from('dirA'), Buffer.from('dirB'), { recursive: true, filter(...args) { console.log(...args); return true; } });  // throws

cp(Buffer.from('dirA'), Buffer.from('dirB'), { recursive: true, filter(...args) { console.log(...args); return true; } }, (err) => {
  console.log(err);  // errors
});

promises.cp(Buffer.from('dirA'), Buffer.from('dirB'), { recursive: true, filter(...args) { console.log(...args); return true; } });  // rejects
How often does it reproduce? Is there a required condition?

Always

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

It should just work without throwing. The filter function should be called with the option to receive the path as either a string, Buffer, or URL.

What do you see instead?

It throws.

Additional information

The issue here is that the underlying implementation assumes that the paths are strings and tries to use the path.join function to concatenate them, which obviously does not work for Buffer and URL. The implementation has to be able to support Buffer and URL paths in order to properly support arbitrary text encodings in file names etc. Unfortunately, because of the way the callback is designed, it's not clear that there is an immediate non-breaking fix ready available.

@dario-piotrowicz @cjihrig @anonrig

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den Einstiegspunkten fs.cpSync, fs.cp und fs.promises.cp und reproduziere das Buffer-Pfad-Beispiel aus dem Issue. Verfolge die Pfadverarbeitung und die Argumente des Filter-Callbacks für Eingaben vom Typ String, Buffer und URL. Fertig ist die Aufgabe, wenn alle drei APIs Buffer- und URL-Pfade akzeptieren, ohne eine Exception auszulösen, und der Filter einen unterstützten Pfadwert erhält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, nodejs
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.