fs.cp and fs.cpSync fail to repeatedly copy directory with symlinks
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
Version
v24.16.0
Platform
Linux machine 7.1.3-cachyos-lto #1-NixOS SMP PREEMPT_DYNAMIC Tue Jan 1 00:00:00 UTC 1980 x86_64 GNU/Linux
Subsystem
fs
What steps will reproduce the bug?
This script reproduces the issue:
root="$(mktemp -d)"
trap 'rm -rf "$root"' EXIT
mkdir "$root/dir" "$root/foo"
ln -s "$root/dir" "$root/foo/link"
ROOT="$root" node <<'NODE'
const fs = require("node:fs");
const root = process.env.ROOT;
fs.cpSync(`${root}/foo`, `${root}/bar`, { recursive: true }); // succeeds
fs.cpSync(`${root}/foo`, `${root}/bar`, { recursive: true }); // throws
NODE
How often does it reproduce? Is there a required condition?
Requires a copying repeatedly a dir containing a symlink to another dir.
What is the expected behavior? Why is that the expected behavior?
The second copy should succeed, replacing bar/link or leaving it unchanged.
What do you see instead?
node:internal/fs/cp/cp-sync:145
return fsBinding.cpSyncCopyDir(src, dest,
^
Error: Cannot copy /tmp/tmp.61ap1tNPej/dir to a subdirectory of self /tmp/tmp.61ap1tNPej/dir
at copyDir (node:internal/fs/cp/cp-sync:145:22)
at onDir (node:internal/fs/cp/cp-sync:137:10)
at getStats (node:internal/fs/cp/cp-sync:68:12)
at cpSyncFn (node:internal/fs/cp/cp-sync:58:10)
at Object.cpSync (node:fs:3158:3)
at [stdin]:5:4
at runScriptInThisContext (node:internal/vm:219:10)
at node:internal/process/execution:451:12
at [stdin]-wrapper:6:24
at runScriptInContext (node:internal/process/execution:449:60) {
code: 'ERR_FS_CP_EINVAL'
}
Node.js v24.16.0
Additional information
Also recreated in:
- Node.js v22.23.1
- Node.js v26.7.0
- Node.js v27.0.0-nightly20260806de333e856d
The result is the same with force: true, force: false, or errorOnExist. fs.cp() and fs.promises.cp() are also affected.
Modifying bar/link, or pointing it to a different directory, makes the second copy succeed.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc tái hiện với node:fs và theo dõi các mục trong stack tại node:internal/fs/cp/cp-sync, đặc biệt là copyDir, onDir và getStats. Kiểm tra trường hợp sao chép đệ quy lặp lại với một symbolic link đến thư mục, sau đó xác minh rằng fs.cpSync, fs.cp và fs.promises.cp hoàn tất thành công lần sao chép thứ hai mà không thay đổi hành vi đã được báo cáo đối với thư mục con của chính nó.
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
- backend, operating-systems
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 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
- 68/100