mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cp, mv: return error for symlinks on non-unix/non-windows platforms
Replace cfg(not(windows)) with cfg(unix) for the symlink_file call, and add a fallback that returns an unsupported error on platforms like WASI that lack symlink support.
This commit is contained in:
committed by
Daniel Hofstetter
parent
dbb4d6f528
commit
6bb15899d5
+11
-1
@@ -1898,7 +1898,17 @@ fn symlink_file(
|
||||
dest: &Path,
|
||||
symlinked_files: &mut HashSet<FileInformation>,
|
||||
) -> CopyResult<()> {
|
||||
#[cfg(not(windows))]
|
||||
#[cfg(target_os = "wasi")]
|
||||
{
|
||||
return Err(CpError::IoErrContext(
|
||||
std::io::Error::new(std::io::ErrorKind::Unsupported, "symlinks not supported"),
|
||||
translate!("cp-error-cannot-create-symlink",
|
||||
"dest" => get_filename(dest).unwrap_or("?").quote(),
|
||||
"source" => get_filename(source).unwrap_or("?").quote()),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
#[cfg(not(any(windows, target_os = "wasi")))]
|
||||
{
|
||||
std::os::unix::fs::symlink(source, dest).map_err(|e| {
|
||||
CpError::IoErrContext(
|
||||
|
||||
+3
-2
@@ -821,6 +821,8 @@ fn rename_with_fallback(
|
||||
const EXDEV: i32 = windows_sys::Win32::Foundation::ERROR_NOT_SAME_DEVICE as _;
|
||||
#[cfg(unix)]
|
||||
const EXDEV: i32 = libc::EXDEV as _;
|
||||
#[cfg(target_os = "wasi")]
|
||||
const EXDEV: i32 = 18; // POSIX EXDEV value
|
||||
|
||||
// We will only copy if:
|
||||
// 1. Files are on different devices (EXDEV error)
|
||||
@@ -926,9 +928,8 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(windows, unix)))]
|
||||
#[cfg(target_os = "wasi")]
|
||||
fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
|
||||
let path_symlink_points_to = fs::read_link(from)?;
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
translate!("mv-error-no-symlink-support"),
|
||||
|
||||
Reference in New Issue
Block a user