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`
This commit is contained in:
1
build.rs
1
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 {
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user