From 72b207de2e12f073d81b86b53ec7ec57de547a21 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 25 Jan 2021 14:34:47 -0800 Subject: [PATCH] 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 --- .../test-programs/wasi-tests/src/bin/path_link.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/test-programs/wasi-tests/src/bin/path_link.rs b/crates/test-programs/wasi-tests/src/bin/path_link.rs index c459d7f794..7a441f4f50 100644 --- a/crates/test-programs/wasi-tests/src/bin/path_link.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_link.rs @@ -134,15 +134,16 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) { // Create a link to a directory 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!( - 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" + let path_link_errno = wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link") + .expect_err("creating a link to a directory should fail") + .raw_error(); + assert!( + 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"); // Create a link to a file with trailing slash