Skip to content

Commit 6bb1589

Browse files
sylvestrecakebaker
authored andcommitted
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.
1 parent dbb4d6f commit 6bb1589

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/uu/cp/src/cp.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,17 @@ fn symlink_file(
18981898
dest: &Path,
18991899
symlinked_files: &mut HashSet<FileInformation>,
19001900
) -> CopyResult<()> {
1901-
#[cfg(not(windows))]
1901+
#[cfg(target_os = "wasi")]
1902+
{
1903+
return Err(CpError::IoErrContext(
1904+
std::io::Error::new(std::io::ErrorKind::Unsupported, "symlinks not supported"),
1905+
translate!("cp-error-cannot-create-symlink",
1906+
"dest" => get_filename(dest).unwrap_or("?").quote(),
1907+
"source" => get_filename(source).unwrap_or("?").quote()),
1908+
)
1909+
.into());
1910+
}
1911+
#[cfg(not(any(windows, target_os = "wasi")))]
19021912
{
19031913
std::os::unix::fs::symlink(source, dest).map_err(|e| {
19041914
CpError::IoErrContext(

src/uu/mv/src/mv.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ fn rename_with_fallback(
821821
const EXDEV: i32 = windows_sys::Win32::Foundation::ERROR_NOT_SAME_DEVICE as _;
822822
#[cfg(unix)]
823823
const EXDEV: i32 = libc::EXDEV as _;
824+
#[cfg(target_os = "wasi")]
825+
const EXDEV: i32 = 18; // POSIX EXDEV value
824826

825827
// We will only copy if:
826828
// 1. Files are on different devices (EXDEV error)
@@ -926,9 +928,8 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
926928
}
927929
}
928930

929-
#[cfg(not(any(windows, unix)))]
931+
#[cfg(target_os = "wasi")]
930932
fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
931-
let path_symlink_points_to = fs::read_link(from)?;
932933
Err(io::Error::new(
933934
io::ErrorKind::Other,
934935
translate!("mv-error-no-symlink-support"),

0 commit comments

Comments
 (0)