redefine crate to use Error everywhere except in wasi
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::handle::HandleRights;
|
||||
use crate::sys::sys_impl::oshandle::RawOsHandle;
|
||||
use crate::wasi::Result;
|
||||
use crate::Result;
|
||||
use std::cell::{Cell, RefCell, RefMut};
|
||||
use std::io;
|
||||
use yanix::dir::Dir;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::sys::osdir::OsDir;
|
||||
use crate::wasi::{Errno, Result};
|
||||
use crate::{Error, Result};
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
|
||||
pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> {
|
||||
@@ -20,7 +20,7 @@ pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> {
|
||||
match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlags::SYMLINK_NOFOLLOW) } {
|
||||
Ok(stat) => {
|
||||
if FileType::from_stat_st_mode(stat.st_mode) == FileType::Directory {
|
||||
return Err(Errno::Isdir);
|
||||
return Err(Error::Isdir);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -56,7 +56,7 @@ pub(crate) fn symlink(old_path: &str, new_dirfd: &OsDir, new_path: &str) -> Resu
|
||||
let new_path = new_path.trim_end_matches('/');
|
||||
match unsafe { fstatat(new_dirfd.as_raw_fd(), new_path, AtFlags::SYMLINK_NOFOLLOW) }
|
||||
{
|
||||
Ok(_) => return Err(Errno::Exist),
|
||||
Ok(_) => return Err(Error::Exist),
|
||||
Err(err) => {
|
||||
log::debug!("path_symlink fstatat error: {:?}", err);
|
||||
}
|
||||
@@ -100,9 +100,9 @@ pub(crate) fn rename(
|
||||
Ok(_) => {
|
||||
// check if destination contains a trailing slash
|
||||
if new_path.contains('/') {
|
||||
return Err(Errno::Notdir);
|
||||
return Err(Error::Notdir);
|
||||
} else {
|
||||
return Err(Errno::Noent);
|
||||
return Err(Error::Noent);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::wasi::{types, Errno, Result};
|
||||
use crate::wasi::types;
|
||||
use crate::{Error, Result};
|
||||
use yanix::clock::{clock_getres, clock_gettime, ClockId};
|
||||
|
||||
pub(crate) fn res_get(clock_id: types::Clockid) -> Result<types::Timestamp> {
|
||||
@@ -11,11 +12,11 @@ pub(crate) fn res_get(clock_id: types::Clockid) -> Result<types::Timestamp> {
|
||||
(timespec.tv_sec as types::Timestamp)
|
||||
.checked_mul(1_000_000_000)
|
||||
.and_then(|sec_ns| sec_ns.checked_add(timespec.tv_nsec as types::Timestamp))
|
||||
.map_or(Err(Errno::Overflow), |resolution| {
|
||||
.map_or(Err(Error::Overflow), |resolution| {
|
||||
// a supported clock can never return zero; this case will probably never get hit, but
|
||||
// make sure we follow the spec
|
||||
if resolution == 0 {
|
||||
Err(Errno::Inval)
|
||||
Err(Error::Inval)
|
||||
} else {
|
||||
Ok(resolution)
|
||||
}
|
||||
@@ -31,5 +32,5 @@ pub(crate) fn time_get(clock_id: types::Clockid) -> Result<types::Timestamp> {
|
||||
(timespec.tv_sec as types::Timestamp)
|
||||
.checked_mul(1_000_000_000)
|
||||
.and_then(|sec_ns| sec_ns.checked_add(timespec.tv_nsec as types::Timestamp))
|
||||
.map_or(Err(Errno::Overflow), Ok)
|
||||
.map_or(Err(Error::Overflow), Ok)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use super::oshandle::RawOsHandle;
|
||||
use crate::sys::osdir::OsDir;
|
||||
use crate::sys::osfile::OsFile;
|
||||
use crate::wasi::{self, types, Result};
|
||||
use crate::wasi::{self, types};
|
||||
use crate::Result;
|
||||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::handle::HandleRights;
|
||||
use crate::sys::sys_impl::oshandle::RawOsHandle;
|
||||
use crate::wasi::Result;
|
||||
use crate::Result;
|
||||
use std::cell::Cell;
|
||||
use std::io;
|
||||
use yanix::dir::Dir;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::sys::osdir::OsDir;
|
||||
use crate::wasi::Result;
|
||||
use crate::Result;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
|
||||
pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> {
|
||||
|
||||
@@ -28,7 +28,8 @@ cfg_if::cfg_if! {
|
||||
|
||||
use crate::handle::HandleRights;
|
||||
use crate::sys::AsFile;
|
||||
use crate::wasi::{types, Errno, Result, RightsExt};
|
||||
use crate::wasi::{types, RightsExt};
|
||||
use crate::{Error, Result};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
@@ -141,98 +142,6 @@ impl From<types::Clockid> for ClockId {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Errno {
|
||||
fn from(err: io::Error) -> Self {
|
||||
match err.raw_os_error() {
|
||||
Some(code) => match code {
|
||||
libc::EPERM => Self::Perm,
|
||||
libc::ENOENT => Self::Noent,
|
||||
libc::ESRCH => Self::Srch,
|
||||
libc::EINTR => Self::Intr,
|
||||
libc::EIO => Self::Io,
|
||||
libc::ENXIO => Self::Nxio,
|
||||
libc::E2BIG => Self::TooBig,
|
||||
libc::ENOEXEC => Self::Noexec,
|
||||
libc::EBADF => Self::Badf,
|
||||
libc::ECHILD => Self::Child,
|
||||
libc::EAGAIN => Self::Again,
|
||||
libc::ENOMEM => Self::Nomem,
|
||||
libc::EACCES => Self::Acces,
|
||||
libc::EFAULT => Self::Fault,
|
||||
libc::EBUSY => Self::Busy,
|
||||
libc::EEXIST => Self::Exist,
|
||||
libc::EXDEV => Self::Xdev,
|
||||
libc::ENODEV => Self::Nodev,
|
||||
libc::ENOTDIR => Self::Notdir,
|
||||
libc::EISDIR => Self::Isdir,
|
||||
libc::EINVAL => Self::Inval,
|
||||
libc::ENFILE => Self::Nfile,
|
||||
libc::EMFILE => Self::Mfile,
|
||||
libc::ENOTTY => Self::Notty,
|
||||
libc::ETXTBSY => Self::Txtbsy,
|
||||
libc::EFBIG => Self::Fbig,
|
||||
libc::ENOSPC => Self::Nospc,
|
||||
libc::ESPIPE => Self::Spipe,
|
||||
libc::EROFS => Self::Rofs,
|
||||
libc::EMLINK => Self::Mlink,
|
||||
libc::EPIPE => Self::Pipe,
|
||||
libc::EDOM => Self::Dom,
|
||||
libc::ERANGE => Self::Range,
|
||||
libc::EDEADLK => Self::Deadlk,
|
||||
libc::ENAMETOOLONG => Self::Nametoolong,
|
||||
libc::ENOLCK => Self::Nolck,
|
||||
libc::ENOSYS => Self::Nosys,
|
||||
libc::ENOTEMPTY => Self::Notempty,
|
||||
libc::ELOOP => Self::Loop,
|
||||
libc::ENOMSG => Self::Nomsg,
|
||||
libc::EIDRM => Self::Idrm,
|
||||
libc::ENOLINK => Self::Nolink,
|
||||
libc::EPROTO => Self::Proto,
|
||||
libc::EMULTIHOP => Self::Multihop,
|
||||
libc::EBADMSG => Self::Badmsg,
|
||||
libc::EOVERFLOW => Self::Overflow,
|
||||
libc::EILSEQ => Self::Ilseq,
|
||||
libc::ENOTSOCK => Self::Notsock,
|
||||
libc::EDESTADDRREQ => Self::Destaddrreq,
|
||||
libc::EMSGSIZE => Self::Msgsize,
|
||||
libc::EPROTOTYPE => Self::Prototype,
|
||||
libc::ENOPROTOOPT => Self::Noprotoopt,
|
||||
libc::EPROTONOSUPPORT => Self::Protonosupport,
|
||||
libc::EAFNOSUPPORT => Self::Afnosupport,
|
||||
libc::EADDRINUSE => Self::Addrinuse,
|
||||
libc::EADDRNOTAVAIL => Self::Addrnotavail,
|
||||
libc::ENETDOWN => Self::Netdown,
|
||||
libc::ENETUNREACH => Self::Netunreach,
|
||||
libc::ENETRESET => Self::Netreset,
|
||||
libc::ECONNABORTED => Self::Connaborted,
|
||||
libc::ECONNRESET => Self::Connreset,
|
||||
libc::ENOBUFS => Self::Nobufs,
|
||||
libc::EISCONN => Self::Isconn,
|
||||
libc::ENOTCONN => Self::Notconn,
|
||||
libc::ETIMEDOUT => Self::Timedout,
|
||||
libc::ECONNREFUSED => Self::Connrefused,
|
||||
libc::EHOSTUNREACH => Self::Hostunreach,
|
||||
libc::EALREADY => Self::Already,
|
||||
libc::EINPROGRESS => Self::Inprogress,
|
||||
libc::ESTALE => Self::Stale,
|
||||
libc::EDQUOT => Self::Dquot,
|
||||
libc::ECANCELED => Self::Canceled,
|
||||
libc::EOWNERDEAD => Self::Ownerdead,
|
||||
libc::ENOTRECOVERABLE => Self::Notrecoverable,
|
||||
libc::ENOTSUP => Self::Notsup,
|
||||
x => {
|
||||
log::debug!("Unknown errno value: {}", x);
|
||||
Self::Io
|
||||
}
|
||||
},
|
||||
None => {
|
||||
log::debug!("Other I/O error: {}", err);
|
||||
Self::Io
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<types::Fdflags> for OFlags {
|
||||
fn from(fdflags: types::Fdflags) -> Self {
|
||||
let mut nix_flags = Self::empty();
|
||||
@@ -297,13 +206,13 @@ impl From<types::Oflags> for OFlags {
|
||||
}
|
||||
|
||||
impl TryFrom<libc::stat> for types::Filestat {
|
||||
type Error = Errno;
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(filestat: libc::stat) -> Result<Self> {
|
||||
fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<types::Timestamp> {
|
||||
secs.checked_mul(1_000_000_000)
|
||||
.and_then(|sec_nsec| sec_nsec.checked_add(nsecs))
|
||||
.ok_or(Errno::Overflow)
|
||||
.ok_or(Error::Overflow)
|
||||
}
|
||||
|
||||
let filetype = yanix::file::FileType::from_stat_st_mode(filestat.st_mode);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::handle::{Handle, HandleRights};
|
||||
use crate::sys::osdir::OsDir;
|
||||
use crate::sys::AsFile;
|
||||
use crate::wasi::{types, Errno, Result};
|
||||
use crate::wasi::types;
|
||||
use crate::{Error, Result};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::File;
|
||||
@@ -144,7 +145,7 @@ pub(crate) fn open(
|
||||
match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlags::SYMLINK_NOFOLLOW) } {
|
||||
Ok(stat) => {
|
||||
if FileType::from_stat_st_mode(stat.st_mode) == FileType::Socket {
|
||||
return Err(Errno::Notsup);
|
||||
return Err(Error::Notsup);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -160,7 +161,7 @@ pub(crate) fn open(
|
||||
match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlags::SYMLINK_NOFOLLOW) } {
|
||||
Ok(stat) => {
|
||||
if FileType::from_stat_st_mode(stat.st_mode) == FileType::Symlink {
|
||||
return Err(Errno::Loop);
|
||||
return Err(Error::Loop);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -171,7 +172,7 @@ pub(crate) fn open(
|
||||
// FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on
|
||||
// a symlink.
|
||||
libc::EMLINK if !(nix_all_oflags & OFlags::NOFOLLOW).is_empty() => {
|
||||
return Err(Errno::Loop);
|
||||
return Err(Error::Loop);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -235,7 +236,7 @@ pub(crate) fn filestat_set_times_at(
|
||||
let set_mtim_now = fst_flags.contains(&types::Fstflags::MTIM_NOW);
|
||||
|
||||
if (set_atim && set_atim_now) || (set_mtim && set_mtim_now) {
|
||||
return Err(Errno::Inval);
|
||||
return Err(Error::Inval);
|
||||
}
|
||||
|
||||
let atim = if set_atim {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::entry::EntryHandle;
|
||||
use crate::poll::{ClockEventData, FdEventData};
|
||||
use crate::sys::AsFile;
|
||||
use crate::wasi::{types, Errno, Result};
|
||||
use crate::wasi::types;
|
||||
use crate::{Error, Result};
|
||||
use std::io;
|
||||
use std::{convert::TryInto, os::unix::prelude::AsRawFd};
|
||||
use yanix::file::fionread;
|
||||
@@ -64,7 +65,7 @@ pub(crate) fn oneoff(
|
||||
fn handle_timeout_event(timeout: ClockEventData, events: &mut Vec<types::Event>) {
|
||||
events.push(types::Event {
|
||||
userdata: timeout.userdata,
|
||||
error: Errno::Success,
|
||||
error: types::Errno::Success,
|
||||
type_: types::Eventtype::Clock,
|
||||
fd_readwrite: types::EventFdReadwrite {
|
||||
flags: types::Eventrwflags::empty(),
|
||||
@@ -110,7 +111,7 @@ fn handle_fd_event(
|
||||
let output_event = if revents.contains(PollFlags::POLLNVAL) {
|
||||
types::Event {
|
||||
userdata: fd_event.userdata,
|
||||
error: Errno::Badf,
|
||||
error: Error::Badf.into(),
|
||||
type_: fd_event.r#type,
|
||||
fd_readwrite: types::EventFdReadwrite {
|
||||
nbytes: 0,
|
||||
@@ -120,7 +121,7 @@ fn handle_fd_event(
|
||||
} else if revents.contains(PollFlags::POLLERR) {
|
||||
types::Event {
|
||||
userdata: fd_event.userdata,
|
||||
error: Errno::Io,
|
||||
error: Error::Io.into(),
|
||||
type_: fd_event.r#type,
|
||||
fd_readwrite: types::EventFdReadwrite {
|
||||
nbytes: 0,
|
||||
@@ -130,7 +131,7 @@ fn handle_fd_event(
|
||||
} else if revents.contains(PollFlags::POLLHUP) {
|
||||
types::Event {
|
||||
userdata: fd_event.userdata,
|
||||
error: Errno::Success,
|
||||
error: types::Errno::Success,
|
||||
type_: fd_event.r#type,
|
||||
fd_readwrite: types::EventFdReadwrite {
|
||||
nbytes: 0,
|
||||
@@ -140,7 +141,7 @@ fn handle_fd_event(
|
||||
} else if revents.contains(PollFlags::POLLIN) | revents.contains(PollFlags::POLLOUT) {
|
||||
types::Event {
|
||||
userdata: fd_event.userdata,
|
||||
error: Errno::Success,
|
||||
error: types::Errno::Success,
|
||||
type_: fd_event.r#type,
|
||||
fd_readwrite: types::EventFdReadwrite {
|
||||
nbytes: nbytes.try_into()?,
|
||||
|
||||
Reference in New Issue
Block a user