Skip to content

Commit

Permalink
Map EACCES -> EPERM for hard links to directories
Browse files Browse the repository at this point in the history
  • Loading branch information
marmistrz committed Apr 2, 2020
1 parent 05a376e commit 788dc8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
13 changes: 6 additions & 7 deletions crates/test-programs/wasi-tests/src/bin/path_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "subdir").expect("creating a subdirectory");
create_or_open(dir_fd, "subdir", wasi::OFLAGS_DIRECTORY);

let err = wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link")
.expect_err("creating a link to a directory should fail")
.raw_error();
assert!(
err == wasi::ERRNO_PERM || err == wasi::ERRNO_ACCES,
"errno should be ERRNO_PERM or ERRNO_ACCESS, was: {}",
err
assert_eq!(
wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link")
.expect_err("creating a link to a directory should fail")
.raw_error(),
wasi::ERRNO_PERM,
"errno should be ERRNO_PERM"
);
wasi::path_remove_directory(dir_fd, "subdir").expect("removing a subdirectory");

Expand Down
9 changes: 5 additions & 4 deletions crates/wasi-common/src/sys/windows/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ pub(crate) fn link(
Some(code) => {
debug!("path_link at fs::hard_link error code={:?}", code);
match code as u32 {
// TODO is this needed at all????
winerror::ERROR_ACCESS_DENIED => {
// does the target exist?
if new_path.exists() {
return Err(Errno::Exist);
// If an attempt is made to create a hard link to a directory, POSIX-compliant
// implementations of link return `EPERM`, but `ERROR_ACCESS_DENIED` is converted
// to `EACCES`. We detect and correct this case here.
if fs::metadata(&old_path).map(|m| m.is_dir()).unwrap_or(false) {
return Err(Errno::Perm);
}
}
_ => {}
Expand Down

0 comments on commit 788dc8c

Please sign in to comment.