path_link: some improvements required by windows

* need to close the handle to the subdirectory before its legal to
  delete it
* windows doesnt give us a way to distinguish between an ERRNO_PERM and
  an ERRNO_ACCES, so lets accept either one
This commit is contained in:
Pat Hickey
2021-01-25 14:34:47 -08:00
parent 2c6bde5ee4
commit 72b207de2e

View File

@@ -134,15 +134,16 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
// Create a link to a directory // Create a link to a directory
wasi::path_create_directory(dir_fd, "subdir").expect("creating a subdirectory"); wasi::path_create_directory(dir_fd, "subdir").expect("creating a subdirectory");
create_or_open(dir_fd, "subdir", wasi::OFLAGS_DIRECTORY); let subdir_fd = create_or_open(dir_fd, "subdir", wasi::OFLAGS_DIRECTORY);
assert_eq!( let path_link_errno = wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link")
wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link")
.expect_err("creating a link to a directory should fail") .expect_err("creating a link to a directory should fail")
.raw_error(), .raw_error();
wasi::ERRNO_PERM, assert!(
"errno should be ERRNO_PERM" path_link_errno == wasi::ERRNO_PERM || path_link_errno == wasi::ERRNO_ACCES,
"errno should be ERRNO_PERM or ERRNO_ACCES"
); );
wasi::fd_close(subdir_fd).expect("close subdir before deleting it");
wasi::path_remove_directory(dir_fd, "subdir").expect("removing a subdirectory"); wasi::path_remove_directory(dir_fd, "subdir").expect("removing a subdirectory");
// Create a link to a file with trailing slash // Create a link to a file with trailing slash