nodejs / nodejs/node

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

Đang mở
#58,634 12 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

confirmed-bug fs
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.4k
Merge trung bình
4 ngày 3 giờ
Pull request đã merge (30 ngày)
272

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các entry point fs.cpSync, fs.cp và fs.promises.cp, rồi tái hiện ví dụ về đường dẫn Buffer trong issue. Theo dõi cách xử lý đường dẫn và các đối số của filter callback đối với đầu vào kiểu string, Buffer và URL. Hoàn tất khi cả ba API đều chấp nhận đường dẫn Buffer và URL mà không ném ra exception, đồng thời filter nhận được một giá trị đường dẫn được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, nodejs
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.