Description
Currently, Unix and Windows expose std::os::unix::symlink
and std::os::windows::fs::symlink_file
correspondingly, which both simply accept source and destination by Path
.
However, the currently exposed WASI method - std::os::wasi::fs::symlink
is lower-level and requires user to have a file descriptor of the preopened directory in addition to the file paths:
rust/src/libstd/sys/wasi/ext/fs.rs
Lines 397 to 405 in 8a79d08
This is different from all other fs
methods and not ideal, because it requires calling even more lower-level methods to find and retrieve that preopened directory by file path first, and libpreopen isn't exposed to users, so they have to do this all manually.
Moreover, the codebase already contains a higher-level helper for symlinking files by path and hiding these syscall details, it's just not currently exposed to users:
rust/src/libstd/sys/wasi/fs.rs
Lines 538 to 541 in a605441
If this is not too late in terms of backwards compatibility, it would be better to remove the currently exposed low-level syscall and expose this helper instead, so that users could work on paths more easily like they do on other platforms.
Alternatively, it's necessary to at least expose helpers for retrieving the preopen directory from a file path, as otherwise it's not possible to construct symlinks from userland without invoking raw syscalls.