Skip to content

Commit

Permalink
check and fix non-linux impls
Browse files Browse the repository at this point in the history
  • Loading branch information
iximeow committed Feb 19, 2020
1 parent 4453392 commit 728ec70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 14 additions & 7 deletions crates/wasi-common/src/sys/unix/bsd/hostcalls_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::fdentry::Descriptor;
use crate::hostcalls_impl::PathGet;
use crate::{Error, Result};
use std::os::unix::prelude::AsRawFd;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi-common/src/sys/windows/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub(crate) fn path_readlink(resolved: PathGet, buf: &mut [u8]) -> Result<usize>
// 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)
Expand Down Expand Up @@ -402,7 +402,7 @@ pub(crate) fn path_readlink(resolved: PathGet, buf: &mut [u8]) -> Result<usize>
fn strip_trailing_slashes_and_concatenate(resolved: &PathGet) -> Result<Option<PathBuf>> {
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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 728ec70

Please sign in to comment.