Skip to content

Commit 6a3d902

Browse files
committed
cp: use stat for dest existence check to support LD_PRELOAD
1 parent b583af4 commit 6a3d902

2 files changed

Lines changed: 2 additions & 15 deletions

File tree

src/uu/cp/src/cp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,8 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
13901390
let dest = construct_dest_path(source, target, target_type, options)
13911391
.unwrap_or_else(|_| target.to_path_buf());
13921392

1393-
if FileInformation::from_path(&dest, false).is_ok_and(|info| !info.is_symlink())
1393+
if FileInformation::from_path(&dest, true).is_ok()
1394+
&& !fs::symlink_metadata(&dest).is_ok_and(|m| m.file_type().is_symlink())
13941395
// if both `source` and `dest` are symlinks, it should be considered as an overwrite.
13951396
|| fs::metadata(source).is_ok()
13961397
&& fs::symlink_metadata(source)?.file_type().is_symlink()

src/uucore/src/lib/features/fs.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,6 @@ impl FileInformation {
166166
#[cfg(any(target_os = "netbsd", not(target_pointer_width = "64")))]
167167
return self.0.st_ino.into();
168168
}
169-
170-
// The concept of symlinks doesn't map exactly to Windows (which has reparse
171-
// points, junctions, etc.), so having our own method lets us control what
172-
// we consider a symlink across platforms.
173-
#[cfg(unix)]
174-
pub fn is_symlink(&self) -> bool {
175-
(self.0.st_mode as mode_t & S_IFMT) == S_IFLNK
176-
}
177-
178-
#[cfg(windows)]
179-
pub fn is_symlink(&self) -> bool {
180-
use windows_sys::Win32::Storage::FileSystem::FILE_ATTRIBUTE_REPARSE_POINT;
181-
self.0.file_attributes() & u64::from(FILE_ATTRIBUTE_REPARSE_POINT) != 0
182-
}
183169
}
184170

185171
#[cfg(unix)]

0 commit comments

Comments
 (0)