This commit is contained in:
Marcin Mielniczuk
2019-09-08 08:15:33 +02:00
committed by Jakub Konka
parent b09f7e860f
commit 3fd0cdcc12
5 changed files with 17 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
{ {
"editor.formatOnSave": true, "editor.formatOnSave": true,
"rust-client.disableRustup": false, "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.sysroot": "/home/marcin/.rustup/toolchains/stable-x86_64-pc-windows-gnu/",
"rust.all_targets": false "rust.all_targets": false
} }

View File

@@ -134,11 +134,18 @@ impl Error {
pub(crate) fn as_wasi_errno(&self) -> host::__wasi_errno_t { pub(crate) fn as_wasi_errno(&self) -> host::__wasi_errno_t {
match self { match self {
Self::Wasi(no) => no.as_raw_errno(), Self::Wasi(no) => no.as_raw_errno(),
Self::Io(e) => errno_from_ioerror(e.to_owned()),
#[cfg(unix)] #[cfg(unix)]
Self::Nix(err) => { Self::Nix(err) => err
crate::sys::host_impl::errno_from_nix(err.as_errno().unwrap()).as_wasi_errno() .as_errno()
} // FIXME unwrap .map_or_else(
Self::Io(e) => errno_from_ioerror(e.to_owned()), // fixme clone || {
log::debug!("Unknown nix errno: {}", err);
Self::ENOSYS
},
crate::sys::host_impl::errno_from_nix,
)
.as_wasi_errno(),
#[cfg(windows)] #[cfg(windows)]
Self::Win(err) => crate::sys::host_impl::errno_from_win(*err), Self::Win(err) => crate::sys::host_impl::errno_from_win(*err),
} }

View File

@@ -178,8 +178,6 @@ pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_f
pub(crate) fn filestat_from_nix( pub(crate) fn filestat_from_nix(
filestat: nix::sys::stat::FileStat, filestat: nix::sys::stat::FileStat,
) -> Result<host::__wasi_filestat_t> { ) -> Result<host::__wasi_filestat_t> {
use std::convert::TryFrom;
fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<host::__wasi_timestamp_t> { fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<host::__wasi_timestamp_t> {
secs.checked_mul(1_000_000_000) secs.checked_mul(1_000_000_000)
.and_then(|sec_nsec| sec_nsec.checked_add(nsecs)) .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 filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode);
let dev = host::__wasi_device_t::try_from(filestat.st_dev)?; let dev = host::__wasi_device_t::from(filestat.st_dev);
let ino = host::__wasi_inode_t::try_from(filestat.st_ino)?; 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_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_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)?; let st_mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?;

View File

@@ -442,8 +442,7 @@ pub(crate) fn path_filestat_set_times(
}; };
let fd = resolved.dirfd().as_raw_fd().into(); let fd = resolved.dirfd().as_raw_fd().into();
utimensat(fd, resolved.path(), &atim, &mtim, atflags) utimensat(fd, resolved.path(), &atim, &mtim, atflags).map_err(Into::into)
.map_err(|e| host_impl::errno_from_nix(e.as_errno().unwrap()))
} }
pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> { pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> {

View File

@@ -50,7 +50,7 @@ pub(crate) fn openat(dirfd: &File, path: &str) -> Result<File> {
Mode::empty(), Mode::empty(),
) )
.map(|new_fd| unsafe { File::from_raw_fd(new_fd) }) .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<String> { pub(crate) fn readlinkat(dirfd: &File, path: &str) -> Result<String> {
@@ -60,7 +60,7 @@ pub(crate) fn readlinkat(dirfd: &File, path: &str) -> Result<String> {
let readlink_buf = &mut [0u8; libc::PATH_MAX as usize + 1]; let readlink_buf = &mut [0u8; libc::PATH_MAX as usize + 1];
fcntl::readlinkat(dirfd.as_raw_fd(), path, readlink_buf) 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) .and_then(host_impl::path_from_host)
} }