From 6bb15899d5ebbafd41ea21ad642f2eef852c6fe8 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 30 Mar 2026 21:16:32 +0200 Subject: [PATCH] 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. --- src/uu/cp/src/cp.rs | 12 +++++++++++- src/uu/mv/src/mv.rs | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index e781cc14b..af1243779 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1898,7 +1898,17 @@ fn symlink_file( dest: &Path, symlinked_files: &mut HashSet, ) -> 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( diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 2f69801e1..fa106ac82 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -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"),