From bb5c879718e7fe52f84aa27ec1aab881640d6e71 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 28 Oct 2019 22:49:50 +0100 Subject: [PATCH] Fixes path_symlink_trailing_slashes on Windows This commit: * adds missing `ERROR_ALREADY_EXISTS => __WASI_EEXIST` mapping * re-routes Win errors into correct WASI values in `symlink_*` fns when target exists and/or contains a trailing slash * remaps `ERROR_INVALID_NAME => __WASI_ENOENT` --- build.rs | 1 - src/sys/windows/host_impl.rs | 3 ++- src/sys/windows/hostcalls_impl/fs.rs | 18 ++++++++++++++++++ winx/src/winerror.rs | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index d25c339ca5..48ca7d4319 100644 --- a/build.rs +++ b/build.rs @@ -200,7 +200,6 @@ mod wasm_tests { "truncation_rights" => true, "fd_readdir" => true, "path_rename_trailing_slashes" => true, - "path_symlink_trailing_slashes" => true, _ => false, } } else { diff --git a/src/sys/windows/host_impl.rs b/src/sys/windows/host_impl.rs index 5050cbd46c..284677672c 100644 --- a/src/sys/windows/host_impl.rs +++ b/src/sys/windows/host_impl.rs @@ -22,7 +22,7 @@ pub(crate) fn errno_from_win(error: winx::winerror::WinError) -> host::__wasi_er ERROR_SHARING_VIOLATION => host::__WASI_EACCES, ERROR_PRIVILEGE_NOT_HELD => host::__WASI_ENOTCAPABLE, // TODO is this the correct mapping? ERROR_INVALID_HANDLE => host::__WASI_EBADF, - ERROR_INVALID_NAME => host::__WASI_EINVAL, + ERROR_INVALID_NAME => host::__WASI_ENOENT, ERROR_NOT_ENOUGH_MEMORY => host::__WASI_ENOMEM, ERROR_OUTOFMEMORY => host::__WASI_ENOMEM, ERROR_DIR_NOT_EMPTY => host::__WASI_ENOTEMPTY, @@ -35,6 +35,7 @@ pub(crate) fn errno_from_win(error: winx::winerror::WinError) -> host::__wasi_er ERROR_NOT_A_REPARSE_POINT => host::__WASI_EINVAL, ERROR_NEGATIVE_SEEK => host::__WASI_EINVAL, ERROR_DIRECTORY => host::__WASI_ENOTDIR, + ERROR_ALREADY_EXISTS => host::__WASI_EEXIST, _ => host::__WASI_ENOTSUP, } } diff --git a/src/sys/windows/hostcalls_impl/fs.rs b/src/sys/windows/hostcalls_impl/fs.rs index e8c195c9b2..ad8726987e 100644 --- a/src/sys/windows/hostcalls_impl/fs.rs +++ b/src/sys/windows/hostcalls_impl/fs.rs @@ -346,6 +346,24 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> { // try creating a dir symlink instead symlink_dir(old_path, new_path).map_err(Into::into) } + WinError::ERROR_ACCESS_DENIED => { + // does the target exist? + if new_path.exists() { + Err(Error::EEXIST) + } else { + Err(WinError::ERROR_ACCESS_DENIED.into()) + } + } + WinError::ERROR_INVALID_NAME => { + // does the target without trailing slashes exist? + let suffix = resolved.path().trim_end_matches('/'); + let out_path = concatenate(resolved.dirfd(), Path::new(suffix))?; + if out_path.exists() { + Err(Error::EEXIST) + } else { + Err(WinError::ERROR_INVALID_NAME.into()) + } + } e => Err(e.into()), } } diff --git a/winx/src/winerror.rs b/winx/src/winerror.rs index 12392558c0..bc4e39b331 100644 --- a/winx/src/winerror.rs +++ b/winx/src/winerror.rs @@ -86,6 +86,8 @@ win_error_expand! { ERROR_NEGATIVE_SEEK, /// The directory name is invalid. ERROR_DIRECTORY, + /// Cannot create a file when that file already exists. + ERROR_ALREADY_EXISTS, } impl WinError {