diff --git a/crates/wasi-common/src/sys/unix/bsd/hostcalls_impl.rs b/crates/wasi-common/src/sys/unix/bsd/hostcalls_impl.rs index e0072ccff802..acf0dd632904 100644 --- a/crates/wasi-common/src/sys/unix/bsd/hostcalls_impl.rs +++ b/crates/wasi-common/src/sys/unix/bsd/hostcalls_impl.rs @@ -1,4 +1,3 @@ -use crate::fdentry::Descriptor; use crate::hostcalls_impl::PathGet; use crate::{Error, Result}; use std::os::unix::prelude::AsRawFd; @@ -28,9 +27,13 @@ pub(crate) fn path_unlink_file(resolved: PathGet) -> Result<()> { use yanix::file::{fstatat, SFlag}; if errno == Errno::EPERM { - if let Ok(stat) = - unsafe { fstatat(file.as_raw_fd(), resolved.path(), AtFlag::SYMLINK_NOFOLLOW) } - { + if let Ok(stat) = unsafe { + fstatat( + resolved.dirfd().as_raw_fd(), + resolved.path(), + AtFlag::SYMLINK_NOFOLLOW, + ) + } { if SFlag::from_bits_truncate(stat.st_mode).contains(SFlag::IFDIR) { errno = Errno::EISDIR; } @@ -65,9 +68,13 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> { // the trailing slash and check if the path exists, and // adjust the error code appropriately. let new_path = resolved.path().trim_end_matches('/'); - if let Ok(_) = - unsafe { fstatat(file.as_raw_fd(), new_path, AtFlag::SYMLINK_NOFOLLOW) } - { + if let Ok(_) = unsafe { + fstatat( + resolved.dirfd().as_raw_fd(), + new_path, + AtFlag::SYMLINK_NOFOLLOW, + ) + } { Err(Error::EEXIST) } else { Err(Error::ENOTDIR) diff --git a/crates/wasi-common/src/sys/windows/hostcalls_impl/fs.rs b/crates/wasi-common/src/sys/windows/hostcalls_impl/fs.rs index bd31abe05d2a..ca4299089d6d 100644 --- a/crates/wasi-common/src/sys/windows/hostcalls_impl/fs.rs +++ b/crates/wasi-common/src/sys/windows/hostcalls_impl/fs.rs @@ -372,7 +372,7 @@ pub(crate) fn path_readlink(resolved: PathGet, buf: &mut [u8]) -> Result // we need to strip the prefix from the absolute path // as otherwise we will error out since WASI is not capable // of dealing with absolute paths - let dir_path = get_file_path(file)?; + let dir_path = get_file_path(&resolved.dirfd().as_os_handle())?; let dir_path = PathBuf::from(strip_extended_prefix(dir_path)); let target_path = target_path .strip_prefix(dir_path) @@ -402,7 +402,7 @@ pub(crate) fn path_readlink(resolved: PathGet, buf: &mut [u8]) -> Result fn strip_trailing_slashes_and_concatenate(resolved: &PathGet) -> Result> { if resolved.path().ends_with('/') { let suffix = resolved.path().trim_end_matches('/'); - concatenate(file, Path::new(suffix)).map(Some) + concatenate(&resolved.dirfd().as_os_handle(), Path::new(suffix)).map(Some) } else { Ok(None) } @@ -502,7 +502,7 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> { use std::os::windows::fs::{symlink_dir, symlink_file}; use winx::winerror::WinError; - let old_path = concatenate(file, Path::new(old_path))?; + let old_path = concatenate(&resolved.dirfd().as_os_handle(), Path::new(old_path))?; let new_path = resolved.concatenate()?; // try creating a file symlink