Skip to content

Commit d22b3d5

Browse files
authored
Update to rustix 1.0. (#389)
rustix's procfs module has moved to a separate crate, rustix-linux-procfs.
1 parent 2bc59a3 commit d22b3d5

File tree

13 files changed

+65
-52
lines changed

13 files changed

+65
-52
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ libc = "0.2.100"
3333
io-lifetimes = "2.0.0"
3434

3535
[target.'cfg(not(windows))'.dev-dependencies]
36-
rustix = { version = "0.38.0", features = ["fs"] }
36+
rustix = { version = "1.0.0", features = ["fs"] }
3737

3838
[target.'cfg(windows)'.dev-dependencies]
3939
# nt_version uses internal Windows APIs, however we're only using it

cap-async-std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ io-extras = { version = "0.18.3", features = ["use_async_std"] }
2121
camino = { version = "1.0.5", optional = true }
2222

2323
[target.'cfg(not(windows))'.dependencies]
24-
rustix = { version = "0.38.0", features = ["fs"] }
24+
rustix = { version = "1.0.0", features = ["fs"] }
2525

2626
[features]
2727
default = []

cap-directories/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cap-std = { path = "../cap-std", version = "^3.4.3" }
1717
directories-next = "2.0.0"
1818

1919
[target.'cfg(not(windows))'.dependencies]
20-
rustix = { version = "0.38.0" }
20+
rustix = { version = "1.0.0" }
2121

2222
[target.'cfg(windows)'.dependencies.windows-sys]
2323
version = ">=0.52, <=0.59"

cap-net-ext/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ edition = "2021"
1515
[dependencies]
1616
cap-std = { path = "../cap-std", version = "^3.4.3" }
1717
cap-primitives = { path = "../cap-primitives", version = "^3.4.3" }
18-
rustix = { version = "0.38.0", features = ["net"] }
18+
rustix = { version = "1.0.0", features = ["net"] }
1919
smallvec = "1.10"

cap-net-ext/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,7 @@ impl TcpListenerExt for TcpListener {
158158
set_socket_flags(&stream, blocking)?;
159159

160160
// We know have a TCP socket, so we know we'll get an IP address.
161-
let addr = match addr {
162-
Some(rustix::net::SocketAddrAny::V4(v4)) => SocketAddr::V4(v4),
163-
Some(rustix::net::SocketAddrAny::V6(v6)) => SocketAddr::V6(v6),
164-
_ => unreachable!(),
165-
};
161+
let addr = SocketAddr::try_from(addr.unwrap()).unwrap();
166162

167163
Ok((TcpStream::from(stream), addr))
168164
}

cap-primitives/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ io-lifetimes = { version = "2.0.0", default-features = false }
2525
cap-tempfile = { path = "../cap-tempfile" }
2626

2727
[target.'cfg(not(windows))'.dependencies]
28-
rustix = { version = "0.38.38", features = ["fs", "process", "procfs", "termios", "time"] }
28+
rustix = { version = "1.0.0", features = ["fs", "process", "termios", "time"] }
29+
30+
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
31+
rustix-linux-procfs = "0.1.1"
2932

3033
[target.'cfg(windows)'.dependencies]
3134
winx = "0.36.0"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1-
use rustix::fs::is_file_read_write;
1+
use rustix::fd::{AsFd, BorrowedFd};
2+
use rustix::fs::{fcntl_getfl, OFlags};
23
use std::{fs, io};
34

45
#[inline]
56
pub(crate) fn is_file_read_write_impl(file: &fs::File) -> io::Result<(bool, bool)> {
67
Ok(is_file_read_write(file)?)
78
}
9+
10+
/// `fcntl(fd, F_GETFL) & O_ACCMODE`
11+
///
12+
/// Returns a pair of booleans indicating whether the file descriptor is
13+
/// readable and/or writable, respectively. This is only reliable on files; for
14+
/// example, it doesn't reflect whether sockets have been shut down; for
15+
/// general I/O handle support, use [`io::is_read_write`].
16+
#[inline]
17+
fn is_file_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> {
18+
_is_file_read_write(fd.as_fd())
19+
}
20+
21+
fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> {
22+
let mode = fcntl_getfl(fd)?;
23+
24+
// Check for `O_PATH`.
25+
#[cfg(any(
26+
target_os = "linux",
27+
target_os = "android",
28+
target_os = "emscripten",
29+
target_os = "fuchsia"
30+
))]
31+
if mode.contains(OFlags::PATH) {
32+
return Ok((false, false));
33+
}
34+
35+
// Use `RWMODE` rather than `ACCMODE` as `ACCMODE` may include `O_PATH`.
36+
// We handled `O_PATH` above.
37+
match mode & OFlags::RWMODE {
38+
OFlags::RDONLY => Ok((true, false)),
39+
OFlags::RDWR => Ok((true, true)),
40+
OFlags::WRONLY => Ok((false, true)),
41+
_ => unreachable!(),
42+
}
43+
}

cap-primitives/src/rustix/fs/metadata_ext.rs

+11-36
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ impl ImplMetadataExt {
102102
#[inline]
103103
#[allow(unused_comparisons)] // NB: rust-lang/rust#115823 requires this here instead of on `st_dev` processing below
104104
pub(crate) fn from_rustix(stat: Stat) -> Metadata {
105-
#[cfg(not(target_os = "wasi"))]
106-
use rustix::fs::StatExt;
107-
108105
Metadata {
109106
file_type: ImplFileTypeExt::from_raw_mode(stat.st_mode as RawMode),
110107
len: u64::try_from(stat.st_size).unwrap(),
@@ -113,26 +110,15 @@ impl ImplMetadataExt {
113110
#[cfg(target_os = "wasi")]
114111
permissions: ImplPermissionsExt::default(),
115112

116-
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
117-
modified: system_time_from_rustix(
118-
stat.mtime().try_into().unwrap(),
119-
stat.st_mtime_nsec as _,
120-
),
121-
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
122-
accessed: system_time_from_rustix(
123-
stat.atime().try_into().unwrap(),
124-
stat.st_atime_nsec as _,
125-
),
126-
127-
#[cfg(target_os = "netbsd")]
113+
#[cfg(not(target_os = "wasi"))]
128114
modified: system_time_from_rustix(
129115
stat.st_mtime.try_into().unwrap(),
130-
stat.st_mtimensec as _,
116+
stat.st_mtime_nsec as _,
131117
),
132-
#[cfg(target_os = "netbsd")]
118+
#[cfg(not(target_os = "wasi"))]
133119
accessed: system_time_from_rustix(
134120
stat.st_atime.try_into().unwrap(),
135-
stat.st_atimensec as _,
121+
stat.st_atime_nsec as _,
136122
),
137123

138124
#[cfg(target_os = "wasi")]
@@ -143,6 +129,7 @@ impl ImplMetadataExt {
143129
#[cfg(any(
144130
target_os = "freebsd",
145131
target_os = "openbsd",
132+
target_os = "netbsd",
146133
target_os = "macos",
147134
target_os = "ios",
148135
target_os = "tvos",
@@ -154,12 +141,6 @@ impl ImplMetadataExt {
154141
stat.st_birthtime_nsec as _,
155142
),
156143

157-
#[cfg(target_os = "netbsd")]
158-
created: system_time_from_rustix(
159-
stat.st_birthtime.try_into().unwrap(),
160-
stat.st_birthtimensec as _,
161-
),
162-
163144
// `stat.st_ctime` is the latest status change; we want the creation.
164145
#[cfg(not(any(
165146
target_os = "freebsd",
@@ -200,23 +181,17 @@ impl ImplMetadataExt {
200181
rdev: u64::try_from(stat.st_rdev).unwrap(),
201182
size: u64::try_from(stat.st_size).unwrap(),
202183
#[cfg(not(target_os = "wasi"))]
203-
atime: i64::try_from(stat.atime()).unwrap(),
204-
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
184+
atime: i64::try_from(stat.st_atime).unwrap(),
185+
#[cfg(not(target_os = "wasi"))]
205186
atime_nsec: stat.st_atime_nsec as _,
206-
#[cfg(target_os = "netbsd")]
207-
atime_nsec: stat.st_atimensec as _,
208187
#[cfg(not(target_os = "wasi"))]
209-
mtime: i64::try_from(stat.mtime()).unwrap(),
210-
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
188+
mtime: i64::try_from(stat.st_mtime).unwrap(),
189+
#[cfg(not(target_os = "wasi"))]
211190
mtime_nsec: stat.st_mtime_nsec as _,
212-
#[cfg(target_os = "netbsd")]
213-
mtime_nsec: stat.st_mtimensec as _,
214191
#[cfg(not(target_os = "wasi"))]
215-
ctime: i64::try_from(stat.ctime()).unwrap(),
216-
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
192+
ctime: i64::try_from(stat.st_ctime).unwrap(),
193+
#[cfg(not(target_os = "wasi"))]
217194
ctime_nsec: stat.st_ctime_nsec as _,
218-
#[cfg(target_os = "netbsd")]
219-
ctime_nsec: stat.st_ctimensec as _,
220195
#[cfg(not(target_os = "wasi"))]
221196
blksize: u64::try_from(stat.st_blksize).unwrap(),
222197
#[cfg(not(target_os = "wasi"))]

cap-primitives/src/rustix/linux/fs/procfs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::fs::{
1313
use io_lifetimes::{AsFd, AsFilelike};
1414
use rustix::fs::{chmodat, AtFlags, Mode, OFlags, RawMode};
1515
use rustix::path::DecInt;
16-
use rustix::procfs::proc_self_fd;
16+
use rustix_linux_procfs::proc_self_fd;
1717
use std::os::unix::fs::PermissionsExt;
1818
use std::path::{Path, PathBuf};
1919
use std::{fs, io};

cap-std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ io-lifetimes = { version = "2.0.0", default-features = false }
2424
camino = { version = "1.0.5", optional = true }
2525

2626
[target.'cfg(not(windows))'.dependencies]
27-
rustix = { version = "0.38.0", features = ["fs"] }
27+
rustix = { version = "1.0.0", features = ["fs"] }
2828

2929
[features]
3030
default = []

cap-tempfile/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ camino = { version = "1.0.5", optional = true }
2121
rand = "0.8.1"
2222

2323
[target.'cfg(not(windows))'.dependencies]
24-
rustix = { version = "0.38.0", features = ["procfs"] }
24+
rustix = { version = "1.0.0" }
25+
26+
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
27+
rustix-linux-procfs = "0.1.1"
2528

2629
[target.'cfg(windows)'.dev-dependencies.windows-sys]
2730
version = ">=0.52, <=0.59"

cap-tempfile/src/tempfile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn new_tempfile_linux(d: &Dir, anonymous: bool) -> io::Result<Option<File>> {
8787
fn generate_name_in(subdir: &Dir, f: &File) -> io::Result<String> {
8888
use rustix::fd::AsFd;
8989
use rustix::fs::AtFlags;
90-
let procself_fd = rustix::procfs::proc_self_fd()?;
90+
let procself_fd = rustix_linux_procfs::proc_self_fd()?;
9191
let fdnum = rustix::path::DecInt::from_fd(f.as_fd());
9292
let fdnum = fdnum.as_c_str();
9393
super::retry_with_name_ignoring(io::ErrorKind::AlreadyExists, |name| {

cap-time-ext/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cap-std = { path = "../cap-std", optional = true, version = "^3.4.3" }
1919
iana-time-zone = "0.1.57"
2020

2121
[target.'cfg(not(windows))'.dependencies]
22-
rustix = { version = "0.38.0", features = ["time"] }
22+
rustix = { version = "1.0.0", features = ["time"] }
2323

2424
[target.'cfg(windows)'.dependencies]
2525
once_cell = "1.5.2"

0 commit comments

Comments
 (0)