Repository: vitiral/path_abs (language: rust)

Issue:
WASI symlink implementation is incorrect
Actually, wait, this PR is wrong. The file descriptor in the API is supposed to be a preopen directory descriptor, not the descriptor for the target file.

_Originally posted by @RReverser in https://github.com/vitiral/path_abs/issues/50#issuecomment-770120481_


Discussion / hints:
Until https://github.com/rust-lang/rust/issues/68574 is fixed, it's best to either use symlink via `libc`, or fallback to not supporting them altogether.
I knew that... That's totally why I haven't merged yet...

On Fri, Jan 29, 2021, 6:02 PM Ingvar Stepanyan <notifications@github.com>
wrote:

> Until rust-lang/rust#68574
> <https://github.com/rust-lang/rust/issues/68574> is fixed, it's best to
> either use symlink via libc, or fallback to not supporting them
> altogether.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/vitiral/path_abs/issues/51#issuecomment-770126432>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABKUFSYDPBIH4YN2VG3YAQ3S4NLCJANCNFSM4WZY4HRQ>
> .
>

> That's totally why I haven't merged yet...

Can't tell if you're just joking or I'm misunderstanding what you're saying 🤔 The PR above is merged...
FWIW I meanwhile made a PR to Rust to expose the correct API: https://github.com/rust-lang/rust/pull/81542

Let's see how that goes...
Sorry, I meant it's the reason I haven't pushed and was joking. The reason I haven't pushed is 🅻🅸🅵🅴

I'll hold off on updating the library until someone tells me the implementation is correct. I'd be willing to also accept a PR to add a crate feature for `wasi` and use the wasi crate to implement the "correct" behavior, as suggested in rust-lang/rust#81542
> Sorry, I meant it's the reason I haven't pushed and was joking. The reason I haven't pushed is 🅻🅸🅵🅴

Ah, that's how I understood it first too, but wanted to double-check :)

I have a pending PR to implement correct behaviour for symlinks, but first had to make some PRs to add WASI support to `tempfile` crate which is used for tests in this one.

Now that https://github.com/Stebalien/tempfile/pull/138 is merged, I'll be able to make a PR here soon-ish too.

Fix patch:
diff --git a/src/dir.rs b/src/dir.rs
index 2490e62..41592d4 100644
--- a/src/dir.rs
+++ b/src/dir.rs
@@ -525,8 +525,7 @@ impl PathOps for PathDir {
 
 #[cfg(target_os = "wasi")]
 fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
-    let file = std::fs::File::open(&src)?;
-    std::os::wasi::fs::symlink(src, &file, dst)
+    std::os::wasi::fs::symlink_path(src, dst)
 }
 
 #[cfg(unix)]
diff --git a/src/file.rs b/src/file.rs
index 335d11a..e87e4db 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -572,8 +572,7 @@ impl PathOps for PathFile {
 
 #[cfg(target_os = "wasi")]
 fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
-    let file = std::fs::File::open(&src)?;
-    std::os::wasi::fs::symlink(src, &file, dst)
+    std::os::wasi::fs::symlink_path(src, dst)
 }
 
 #[cfg(unix)]


Test patch: