cp -a exits 0 when an existing directory prevents it from copying a symlink

Đang mở Phù hợp với người mới
#17,001 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu từ src/uu/cp/src/copydir.rs, quanh các dòng được liên kết 294–341, sau đó theo dõi cách copy_direntry xử lý lỗi từ copy_file đối với liên kết tượng trưng khi bật tính năng giữ nguyên liên kết. Tái hiện bằng bộ kiểm thử shell trong issue và so sánh cp -RP với cp -a. Hoàn tất khi trường hợp cp -a báo lỗi sao chép và thoát với mã khác không, khớp với đầu ra mong đợi.

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

Mô tả

When updating a backup, cp -a silently skips a source symlink if its destination is an existing directory. A script can report a successful backup while the current path still serves old contents.

Reproduction

cd "$(mktemp -d)" || exit 1
export LC_ALL=C
mkdir -p src/v2 backup/src/current
printf 'new\n' > src/v2/version
printf 'old\n' > backup/src/current/version
ln -s v2 src/current
cp -a src backup
printf 'cp status: %s\n' "$?"
cat backup/src/current/version

Actual

uutils copies v2, leaves the old current directory in place, and prints no diagnostic.

cp status: 0
old

Expected

GNU coreutils 9.7 and 9.12 preserve the existing directory and report the failed copy.

cp: cannot overwrite directory 'backup/src/current' with non-directory 'src/current'
cp status: 1
old

Cause and tested versions

During recursive traversal, copy_file returns an error when symlink creation fails. With hard-link preservation enabled by -a, copy_direntry discards that error for a source symlink and returns Ok(false). On the same fixture, uutils cp -RP exits 1, while adding --preserve=links reproduces the silent success. Source

Reproduced on x86-64 Debian 13 with uutils release 0.13.0 (07b76df46339) and upstream main (2a072db2938e).

Ngôn ngữ chính
Rust
Star
24.5k
Fork
2.2k
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
325

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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.

Issue khác của uutils/coreutils

Tất cả issue của uutils/coreutils

Issue tương tự

Thêm issue về Rust

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.