Skip to content

Update to io-lifetimes 0.7.0. #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ rand = "0.8.1"
tempfile = "3.1.0"
camino = "1.0.5"
libc = "0.2.100"
io-lifetimes = "0.5.1"
io-lifetimes = "0.7.0"

[target.'cfg(not(windows))'.dev-dependencies]
rustix = "0.33.0"
rustix = { version = "0.35.6", features = ["fs"] }

[target.'cfg(windows)'.dev-dependencies]
# nt_version uses internal Windows APIs, however we're only using it
# for testing here.
nt_version = "0.1.3"
winapi = "0.3.9"
winapi = { version = "0.3.9", features = ["winioctl"] }

[features]
default = []
Expand Down
8 changes: 4 additions & 4 deletions cap-async-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ repository = "https://github.com/bytecodealliance/cap-std"
edition = "2018"

[dependencies]
arf-strings = { version = "0.6.3", optional = true }
arf-strings = { version = "0.6.7", optional = true }
# Enable "unstable" for `spawn_blocking`.
async-std = { version = "1.10.0", features = ["attributes", "unstable"] }
cap-primitives = { path = "../cap-primitives", version = "^0.24.1-alpha.0"}
io-lifetimes = { version = "0.5.1", default-features = false, features = ["async-std"] }
io-lifetimes = { version = "0.7.0", default-features = false, features = ["async-std"] }
ipnet = "2.3.0"
io-extras = { version = "0.13.0", features = ["use_async_std"] }
io-extras = { version = "0.15.0", features = ["use_async_std"] }
camino = { version = "1.0.5", optional = true }

[target.'cfg(not(windows))'.dependencies]
rustix = "0.33.0"
rustix = { version = "0.35.6", features = ["fs"] }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion cap-async-std/src/fs_utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn to_utf8<P: AsRef<async_std::path::Path>>(path: P) -> std::io::Result<Utf8Path
#[cfg(not(windows))]
{
Ok(Utf8Path::from_path(path.as_ref().into())
.ok_or_else(|| ::rustix::io::Error::ILSEQ)?
.ok_or_else(|| ::rustix::io::Errno::ILSEQ)?
.to_path_buf())
}

Expand Down
2 changes: 1 addition & 1 deletion cap-directories/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cap-std = { path = "../cap-std", version = "^0.24.1-alpha.0"}
directories-next = "2.0.0"

[target.'cfg(not(windows))'.dependencies]
rustix = "0.33.0"
rustix = { version = "0.35.6" }

[target.'cfg(windows)'.dependencies]
winapi = "0.3.9"
2 changes: 1 addition & 1 deletion cap-directories/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use user_dirs::UserDirs;

#[cfg(not(windows))]
pub(crate) fn not_found() -> io::Error {
rustix::io::Error::NOENT.into()
rustix::io::Errno::NOENT.into()
}

#[cfg(windows)]
Expand Down
4 changes: 2 additions & 2 deletions cap-fs-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ repository = "https://github.com/bytecodealliance/cap-std"
edition = "2018"

[dependencies]
arf-strings = { version = "0.6.3", optional = true }
arf-strings = { version = "0.6.7", optional = true }
cap-async-std = { path = "../cap-async-std", optional = true, version = "^0.24.1-alpha.0"}
cap-std = { path = "../cap-std", optional = true, version = "^0.24.1-alpha.0"}
cap-primitives = { path = "../cap-primitives", version = "^0.24.1-alpha.0"}
io-lifetimes = { version = "0.5.1", default-features = false }
io-lifetimes = { version = "0.7.0", default-features = false }
# Enable "unstable" for `spawn_blocking`.
async-std = { version = "1.10.0", features = ["attributes", "unstable"], optional = true }
async-trait = { version = "0.1.42", optional = true }
Expand Down
10 changes: 5 additions & 5 deletions cap-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ ambient-authority = "0.0.1"
arbitrary = { version = "1.0.0", optional = true, features = ["derive"] }
ipnet = "2.3.0"
maybe-owned = "0.3.4"
fs-set-times = "0.15.0"
io-extras = "0.13.0"
io-lifetimes = { version = "0.5.1", default-features = false }
fs-set-times = "0.17.0"
io-extras = "0.15.0"
io-lifetimes = { version = "0.7.0", default-features = false }

[target.'cfg(not(windows))'.dependencies]
rustix = { version = "0.33.0", features = ["procfs"] }
rustix = { version = "0.35.6", features = ["fs", "process", "procfs", "termios", "time"] }

[target.'cfg(target_os = "macos")'.dependencies]
errno = { version = "0.2.8", default-features = false }
Expand All @@ -31,6 +31,6 @@ errno = { version = "0.2.8", default-features = false }
errno = { version = "0.2.8", default-features = false }

[target.'cfg(windows)'.dependencies]
winx = "0.31.0"
winx = "0.33.0"
winapi = "0.3.9"
winapi-util = "0.1.5"
16 changes: 8 additions & 8 deletions cap-primitives/src/rustix/fs/copy_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,24 @@ pub(crate) fn copy_impl(
let copy_result = copy_file_range(&reader, None, &writer, None, bytes_to_copy);
if let Err(copy_err) = copy_result {
match copy_err {
rustix::io::Error::NOSYS | rustix::io::Error::PERM => {
rustix::io::Errno::NOSYS | rustix::io::Errno::PERM => {
HAS_COPY_FILE_RANGE.store(false, Ordering::Relaxed);
}
_ => {}
}
}
copy_result
} else {
Err(rustix::io::Error::NOSYS.into())
Err(rustix::io::Errno::NOSYS.into())
};
match copy_result {
Ok(ret) => written += ret as u64,
Err(err) => {
match err {
rustix::io::Error::NOSYS
| rustix::io::Error::XDEV
| rustix::io::Error::INVAL
| rustix::io::Error::PERM => {
rustix::io::Errno::NOSYS
| rustix::io::Errno::XDEV
| rustix::io::Errno::INVAL
| rustix::io::Errno::PERM => {
// Try fallback io::copy if either:
// - Kernel version is < 4.5 (ENOSYS)
// - Files are mounted on different fs (EXDEV)
Expand Down Expand Up @@ -193,10 +193,10 @@ pub(crate) fn copy_impl(
// destination already exists, or if the source and destination
// are on different devices. In all these cases `fcopyfile`
// should succeed.
rustix::io::Error::NOTSUP | rustix::io::Error::EXIST | rustix::io::Error::XDEV => {
rustix::io::Errno::NOTSUP | rustix::io::Errno::EXIST | rustix::io::Errno::XDEV => {
()
}
rustix::io::Error::NOSYS => HAS_FCLONEFILEAT.store(false, Ordering::Relaxed),
rustix::io::Errno::NOSYS => HAS_FCLONEFILEAT.store(false, Ordering::Relaxed),
_ => return Err(err.into()),
},
}
Expand Down
10 changes: 5 additions & 5 deletions cap-primitives/src/rustix/fs/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ use std::io;

#[cold]
pub(crate) fn invalid_flags() -> io::Error {
rustix::io::Error::INVAL.into()
rustix::io::Errno::INVAL.into()
}

#[cold]
pub(crate) fn no_such_file_or_directory() -> io::Error {
rustix::io::Error::NOENT.into()
rustix::io::Errno::NOENT.into()
}

#[cold]
pub(crate) fn is_directory() -> io::Error {
rustix::io::Error::ISDIR.into()
rustix::io::Errno::ISDIR.into()
}

#[cold]
pub(crate) fn is_not_directory() -> io::Error {
rustix::io::Error::NOTDIR.into()
rustix::io::Errno::NOTDIR.into()
}

#[cold]
pub(crate) fn too_many_symlinks() -> io::Error {
rustix::io::Error::LOOP.into()
rustix::io::Errno::LOOP.into()
}
2 changes: 1 addition & 1 deletion cap-primitives/src/rustix/fs/file_path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fs::file_path_by_searching;
#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))]
use rustix::io::ttyname;
use rustix::termios::ttyname;
#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))]
use std::ffi::OsString;
use std::fs;
Expand Down
6 changes: 3 additions & 3 deletions cap-primitives/src/rustix/fs/oflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) fn get_access_mode(options: &OpenOptions) -> io::Result<OFlags> {
(true, true, false) => Ok(OFlags::RDWR),
(false, _, true) => Ok(OFlags::WRONLY | OFlags::APPEND),
(true, _, true) => Ok(OFlags::RDWR | OFlags::APPEND),
(false, false, false) => Err(rustix::io::Error::INVAL.into()),
(false, false, false) => Err(rustix::io::Errno::INVAL.into()),
}
}

Expand All @@ -49,12 +49,12 @@ pub(crate) fn get_creation_mode(options: &OpenOptions) -> io::Result<OFlags> {
(true, false) => {}
(false, false) => {
if options.truncate || options.create || options.create_new {
return Err(rustix::io::Error::INVAL.into());
return Err(rustix::io::Errno::INVAL.into());
}
}
(_, true) => {
if options.truncate && !options.create_new {
return Err(rustix::io::Error::INVAL.into());
return Err(rustix::io::Errno::INVAL.into());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions cap-primitives/src/rustix/fs/open_unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ pub(crate) fn open_unchecked(
// `ELOOP` is the POSIX standard and most widely used error code to
// indicate that a symlink was found when `O_NOFOLLOW` was set.
#[cfg(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd")))]
io::Error::LOOP => Err(OpenUncheckedError::Symlink(err.into(), ())),
io::Errno::LOOP => Err(OpenUncheckedError::Symlink(err.into(), ())),

// FreeBSD and similar (but not Darwin) use `EMLINK`.
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
io::Error::MLINK => Err(OpenUncheckedError::Symlink(err.into(), ())),
io::Errno::MLINK => Err(OpenUncheckedError::Symlink(err.into(), ())),

// NetBSD uses `EFTYPE`.
#[cfg(any(target_os = "netbsd"))]
io::Error::FTYPE => Err(OpenUncheckedError::Symlink(err.into(), ())),
io::Errno::FTYPE => Err(OpenUncheckedError::Symlink(err.into(), ())),

io::Error::NOENT => Err(OpenUncheckedError::NotFound(err.into())),
io::Error::NOTDIR => {
io::Errno::NOENT => Err(OpenUncheckedError::NotFound(err.into())),
io::Errno::NOTDIR => {
if options.dir_required
&& stat_unchecked(start, path, options.follow)
.map(|m| m.file_type().is_symlink())
Expand Down
37 changes: 21 additions & 16 deletions cap-primitives/src/rustix/fs/read_dir_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use crate::fs::{
Metadata, OpenOptions, ReadDir,
};
use io_extras::os::rustix::{AsRawFd, FromRawFd, RawFd};
use io_lifetimes::AsFd;
use io_lifetimes::{AsFd, IntoFd};
use rustix::fs::Dir;
use rustix::io::OwnedFd;
use std::ffi::OsStr;
use std::mem::ManuallyDrop;
#[cfg(unix)]
Expand All @@ -18,15 +19,20 @@ use std::{fmt, fs, io};

pub(crate) struct ReadDirInner {
raw_fd: RawFd,
rustix: Arc<Mutex<Dir>>,

// `Dir` doesn't implement `AsFd`, because libc `fdopendir` has UB if the
// file descriptor is used in almost any way, so we hold a separate
// `OwnedFd` that we can do `as_fd()` on.
rustix: Arc<Mutex<(Dir, OwnedFd)>>,
}

impl ReadDirInner {
pub(crate) fn new(start: &fs::File, path: &Path, follow: FollowSymlinks) -> io::Result<Self> {
let dir = Dir::from(open_dir_for_reading(start, path, follow)?)?;
let fd = open_dir_for_reading(start, path, follow)?;
let dir = Dir::read_from(fd.as_fd())?;
Ok(Self {
raw_fd: dir.as_fd().as_raw_fd(),
rustix: Arc::new(Mutex::new(dir)),
raw_fd: fd.as_fd().as_raw_fd(),
rustix: Arc::new(Mutex::new((dir, fd.into_fd().into()))),
})
}

Expand All @@ -35,14 +41,12 @@ impl ReadDirInner {
// `dup` since in that case the resulting file descriptor would share
// a current position with the original, and `read_dir` calls after
// the first `read_dir` call wouldn't start from the beginning.
let dir = Dir::from(open_dir_for_reading_unchecked(
start,
Component::CurDir.as_ref(),
FollowSymlinks::No,
)?)?;
let fd =
open_dir_for_reading_unchecked(start, Component::CurDir.as_ref(), FollowSymlinks::No)?;
let dir = Dir::read_from(fd.as_fd())?;
Ok(Self {
raw_fd: dir.as_fd().as_raw_fd(),
rustix: Arc::new(Mutex::new(dir)),
raw_fd: fd.as_fd().as_raw_fd(),
rustix: Arc::new(Mutex::new((dir, fd.into_fd().into()))),
})
}

Expand All @@ -51,10 +55,11 @@ impl ReadDirInner {
path: &Path,
follow: FollowSymlinks,
) -> io::Result<Self> {
let dir = open_dir_for_reading_unchecked(start, path, follow)?;
let fd = open_dir_for_reading_unchecked(start, path, follow)?;
let dir = Dir::read_from(fd.as_fd())?;
Ok(Self {
raw_fd: dir.as_fd().as_raw_fd(),
rustix: Arc::new(Mutex::new(Dir::from(dir)?)),
raw_fd: fd.as_fd().as_raw_fd(),
rustix: Arc::new(Mutex::new((dir, fd.into_fd().into()))),
})
}

Expand Down Expand Up @@ -99,7 +104,7 @@ impl Iterator for ReadDirInner {

fn next(&mut self) -> Option<Self::Item> {
loop {
let entry = match self.rustix.lock().unwrap().read()? {
let entry = match self.rustix.lock().unwrap().0.read()? {
Ok(entry) => entry,
Err(e) => return Some(Err(e.into())),
};
Expand Down
12 changes: 6 additions & 6 deletions cap-primitives/src/rustix/fs/set_permissions_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fs::{errors, open, OpenOptions, Permissions};
use rustix::fs::{fchmod, Mode};
use rustix::io::Error;
use rustix::io::Errno;
use std::convert::TryInto;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
Expand All @@ -23,23 +23,23 @@ pub(crate) fn set_permissions_impl(
// access, so first try read.
match open(start, path, OpenOptions::new().read(true)) {
Ok(file) => return set_file_permissions(&file, std_perm),
Err(err) => match Error::from_io_error(&err) {
Some(Error::ACCESS) => (),
Err(err) => match Errno::from_io_error(&err) {
Some(Errno::ACCESS) => (),
_ => return Err(err),
},
}

// Next try write.
match open(start, path, OpenOptions::new().write(true)) {
Ok(file) => return set_file_permissions(&file, std_perm),
Err(err) => match Error::from_io_error(&err) {
Some(Error::ACCESS) | Some(Error::ISDIR) => (),
Err(err) => match Errno::from_io_error(&err) {
Some(Errno::ACCESS) | Some(Errno::ISDIR) => (),
_ => return Err(err),
},
}

// If neither of those worked, we're out of luck.
Err(Error::NOTSUP.into())
Err(Errno::NOTSUP.into())
}

pub(crate) fn set_file_permissions(file: &fs::File, perm: fs::Permissions) -> io::Result<()> {
Expand Down
12 changes: 6 additions & 6 deletions cap-primitives/src/rustix/fs/set_times_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::fs::{open, OpenOptions, SystemTimeSpec};
use fs_set_times::SetTimes;
use rustix::io::Error;
use rustix::io::Errno;
use std::path::Path;
use std::{fs, io};

Expand All @@ -22,8 +22,8 @@ pub(crate) fn set_times_impl(
mtime.map(SystemTimeSpec::into_std),
)
}
Err(err) => match Error::from_io_error(&err) {
Some(Error::ACCESS) | Some(Error::ISDIR) => (),
Err(err) => match Errno::from_io_error(&err) {
Some(Errno::ACCESS) | Some(Errno::ISDIR) => (),
_ => return Err(err),
},
}
Expand All @@ -36,8 +36,8 @@ pub(crate) fn set_times_impl(
mtime.map(SystemTimeSpec::into_std),
)
}
Err(err) => match Error::from_io_error(&err) {
Some(Error::ACCESS) => (),
Err(err) => match Errno::from_io_error(&err) {
Some(Errno::ACCESS) => (),
_ => return Err(err),
},
}
Expand All @@ -51,5 +51,5 @@ pub(crate) fn set_times_impl(
// instead of the file we're trying to get to.
//
// So neither does what we need.
Err(Error::NOTSUP.into())
Err(Errno::NOTSUP.into())
}
Loading