Skip to content

Commit fdd0b1d

Browse files
committed
cp: use lstat for destination check to support LD_PRELOAD tests
1 parent 130f780 commit fdd0b1d

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/uu/cp/src/cp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,8 +1390,7 @@ 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 fs::metadata(&dest).is_ok()
1394-
&& !fs::symlink_metadata(&dest)?.file_type().is_symlink()
1393+
if FileInformation::from_path(&dest, false).is_ok_and(|info| !info.is_symlink())
13951394
// if both `source` and `dest` are symlinks, it should be considered as an overwrite.
13961395
|| fs::metadata(source).is_ok()
13971396
&& fs::symlink_metadata(source)?.file_type().is_symlink()

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ impl FileInformation {
166166
#[cfg(any(target_os = "netbsd", not(target_pointer_width = "64")))]
167167
return self.0.st_ino.into();
168168
}
169+
170+
#[cfg(unix)]
171+
pub fn is_symlink(&self) -> bool {
172+
(self.0.st_mode as mode_t & S_IFMT) == S_IFLNK
173+
}
174+
175+
#[cfg(windows)]
176+
pub fn is_symlink(&self) -> bool {
177+
(self.0.file_attributes() & windows_sys::Win32::Storage::FileSystem::FILE_ATTRIBUTE_REPARSE_POINT) != 0
178+
}
169179
}
170180

171181
#[cfg(unix)]

util/fetch-gnu.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ curl -L "${repo}/releases/download/v${ver}/coreutils-${ver}.tar.xz" | tar --stri
77
curl -L ${repo}/raw/refs/heads/master/tests/mv/hardlink-case.sh > tests/mv/hardlink-case.sh
88
curl -L ${repo}/raw/refs/heads/master/tests/mkdir/writable-under-readonly.sh > tests/mkdir/writable-under-readonly.sh
99
curl -L ${repo}/raw/refs/heads/master/tests/cp/cp-mv-enotsup-xattr.sh > tests/cp/cp-mv-enotsup-xattr.sh #spell-checker:disable-line
10+
curl -L ${repo}/raw/refs/heads/master/tests/cp/nfs-removal-race.sh > tests/cp/nfs-removal-race.sh
1011
curl -L ${repo}/raw/refs/heads/master/tests/csplit/csplit-io-err.sh > tests/csplit/csplit-io-err.sh
1112
# Avoid incorrect PASS
1213
curl -L ${repo}/raw/refs/heads/master/tests/runcon/runcon-compute.sh > tests/runcon/runcon-compute.sh

0 commit comments

Comments
 (0)