diff --git a/.vscode/settings.json b/.vscode/settings.json index 90e722fc0c..fd702539a8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "editor.formatOnSave": true, "rust-client.disableRustup": false, - "rust.target": "x86_64-pc-windows-gnu", + // "rust.target": "x86_64-pc-windows-gnu", //"rust.sysroot": "/home/marcin/.rustup/toolchains/stable-x86_64-pc-windows-gnu/", "rust.all_targets": false } \ No newline at end of file diff --git a/src/error.rs b/src/error.rs index 5fc82db323..ffe79b6aa2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -134,11 +134,18 @@ impl Error { pub(crate) fn as_wasi_errno(&self) -> host::__wasi_errno_t { match self { Self::Wasi(no) => no.as_raw_errno(), + Self::Io(e) => errno_from_ioerror(e.to_owned()), #[cfg(unix)] - Self::Nix(err) => { - crate::sys::host_impl::errno_from_nix(err.as_errno().unwrap()).as_wasi_errno() - } // FIXME unwrap - Self::Io(e) => errno_from_ioerror(e.to_owned()), // fixme clone + Self::Nix(err) => err + .as_errno() + .map_or_else( + || { + log::debug!("Unknown nix errno: {}", err); + Self::ENOSYS + }, + crate::sys::host_impl::errno_from_nix, + ) + .as_wasi_errno(), #[cfg(windows)] Self::Win(err) => crate::sys::host_impl::errno_from_win(*err), } diff --git a/src/sys/unix/host_impl.rs b/src/sys/unix/host_impl.rs index 468d98c3d0..be11942c00 100644 --- a/src/sys/unix/host_impl.rs +++ b/src/sys/unix/host_impl.rs @@ -178,8 +178,6 @@ pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_f pub(crate) fn filestat_from_nix( filestat: nix::sys::stat::FileStat, ) -> Result { - use std::convert::TryFrom; - fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result { secs.checked_mul(1_000_000_000) .and_then(|sec_nsec| sec_nsec.checked_add(nsecs)) @@ -187,8 +185,8 @@ pub(crate) fn filestat_from_nix( } let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode); - let dev = host::__wasi_device_t::try_from(filestat.st_dev)?; - let ino = host::__wasi_inode_t::try_from(filestat.st_ino)?; + let dev = host::__wasi_device_t::from(filestat.st_dev); + let ino = host::__wasi_inode_t::from(filestat.st_ino); let st_atim = filestat_to_timestamp(filestat.st_atime as u64, filestat.st_atime_nsec as u64)?; let st_ctim = filestat_to_timestamp(filestat.st_ctime as u64, filestat.st_ctime_nsec as u64)?; let st_mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?; diff --git a/src/sys/unix/hostcalls_impl/fs.rs b/src/sys/unix/hostcalls_impl/fs.rs index 04dde6277b..bbdc3f5f82 100644 --- a/src/sys/unix/hostcalls_impl/fs.rs +++ b/src/sys/unix/hostcalls_impl/fs.rs @@ -442,8 +442,7 @@ pub(crate) fn path_filestat_set_times( }; let fd = resolved.dirfd().as_raw_fd().into(); - utimensat(fd, resolved.path(), &atim, &mtim, atflags) - .map_err(|e| host_impl::errno_from_nix(e.as_errno().unwrap())) + utimensat(fd, resolved.path(), &atim, &mtim, atflags).map_err(Into::into) } pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> { diff --git a/src/sys/unix/hostcalls_impl/fs_helpers.rs b/src/sys/unix/hostcalls_impl/fs_helpers.rs index 435da35f77..31cd355ba5 100644 --- a/src/sys/unix/hostcalls_impl/fs_helpers.rs +++ b/src/sys/unix/hostcalls_impl/fs_helpers.rs @@ -50,7 +50,7 @@ pub(crate) fn openat(dirfd: &File, path: &str) -> Result { Mode::empty(), ) .map(|new_fd| unsafe { File::from_raw_fd(new_fd) }) - .map_err(|e| host_impl::errno_from_nix(e.as_errno().unwrap())) + .map_err(Into::into) } pub(crate) fn readlinkat(dirfd: &File, path: &str) -> Result { @@ -60,7 +60,7 @@ pub(crate) fn readlinkat(dirfd: &File, path: &str) -> Result { let readlink_buf = &mut [0u8; libc::PATH_MAX as usize + 1]; fcntl::readlinkat(dirfd.as_raw_fd(), path, readlink_buf) - .map_err(|e| host_impl::errno_from_nix(e.as_errno().unwrap())) + .map_err(Into::into) .and_then(host_impl::path_from_host) }