From 291961b117748d902b4dbd53983126a7f3da9f67 Mon Sep 17 00:00:00 2001
From: oech3 <79379754+oech3@users.noreply.github.com>
Date: Mon, 29 Jun 2026 14:52:57 +0900
Subject: [PATCH] cp: dedup nofollow
---
src/uu/cp/src/platform/linux.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/uu/cp/src/platform/linux.rs b/src/uu/cp/src/platform/linux.rs
index 9e556b22440..f3b11f4b56b 100644
--- a/src/uu/cp/src/platform/linux.rs
+++ b/src/uu/cp/src/platform/linux.rs
@@ -74,12 +74,14 @@ fn clone
(source: P, dest: P, fallback: CloneFallback, nofollow: bool) -> std:
where
P: AsRef,
{
- let src_file = open_source(&source, nofollow)?;
- let dst_file = create_dest_restrictive(&dest, false)?;
- if ioctl_ficlone(dst_file, src_file).is_err() {
+ let mut src_file = open_source(&source, nofollow)?;
+ let mut dst_file = create_dest_restrictive(&dest, false)?;
+ if ioctl_ficlone(&dst_file, &src_file).is_err() {
+ // todo: use fd instead of Path to avoid TOCTOU race
return match fallback {
CloneFallback::Error => Err(std::io::Error::last_os_error()),
- CloneFallback::FSCopy => fs_copy(source, dest, nofollow),
+ // already nofollow
+ CloneFallback::FSCopy => buf_copy::copy_stream(&mut src_file, &mut dst_file),
CloneFallback::SparseCopy => sparse_copy(source, dest, nofollow),
CloneFallback::SparseCopyWithoutHole => {
sparse_copy_without_hole(source, dest, nofollow)