1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #7971 from cakebaker/bump_nix_and_ctrlc

Bump `nix` & `ctrlc`, adapt code to API changes in `nix`
This commit is contained in:
Dorian Péron 2025-05-23 12:15:25 +02:00 committed by GitHub
commit aa5dd0e3d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 99 additions and 93 deletions

8
Cargo.lock generated
View file

@ -766,9 +766,9 @@ checksum = "4f211af61d8efdd104f96e57adf5e426ba1bc3ed7a4ead616e15e5881fd79c4d"
[[package]] [[package]]
name = "ctrlc" name = "ctrlc"
version = "3.4.6" version = "3.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "697b5419f348fd5ae2478e8018cb016c00a5881c7f46c717de98ffd135a5651c" checksum = "46f93780a459b7d656ef7f071fe699c4d3d2cb201c4b24d085b6ddc505276e73"
dependencies = [ dependencies = [
"nix", "nix",
"windows-sys 0.59.0", "windows-sys 0.59.0",
@ -1472,9 +1472,9 @@ dependencies = [
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.29.0" version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"cfg-if", "cfg-if",

View file

@ -289,7 +289,7 @@ clap_mangen = "0.2"
compare = "0.1.0" compare = "0.1.0"
coz = { version = "0.1.3" } coz = { version = "0.1.3" }
crossterm = "0.29.0" crossterm = "0.29.0"
ctrlc = { version = "3.4.4", features = ["termination"] } ctrlc = { version = "3.4.7", features = ["termination"] }
dns-lookup = { version = "2.0.4" } dns-lookup = { version = "2.0.4" }
exacl = "0.12.0" exacl = "0.12.0"
file_diff = "1.0.0" file_diff = "1.0.0"
@ -311,7 +311,7 @@ lscolors = { version = "0.20.0", default-features = false, features = [
] } ] }
memchr = "2.7.2" memchr = "2.7.2"
memmap2 = "0.9.4" memmap2 = "0.9.4"
nix = { version = "0.29", default-features = false } nix = { version = "0.30", default-features = false }
nom = "8.0.0" nom = "8.0.0"
notify = { version = "=8.0.0", features = ["macos_kqueue"] } notify = { version = "=8.0.0", features = ["macos_kqueue"] }
num-bigint = "0.4.4" num-bigint = "0.4.4"

92
fuzz/Cargo.lock generated
View file

@ -67,12 +67,12 @@ dependencies = [
[[package]] [[package]]
name = "anstyle-wincon" name = "anstyle-wincon"
version = "3.0.7" version = "3.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"once_cell", "once_cell_polyfill",
"windows-sys", "windows-sys",
] ]
@ -130,9 +130,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.9.0" version = "2.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
[[package]] [[package]]
name = "blake2b_simd" name = "blake2b_simd"
@ -192,9 +192,9 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.20" version = "1.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a" checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766"
dependencies = [ dependencies = [
"jobserver", "jobserver",
"libc", "libc",
@ -248,18 +248,18 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.37" version = "4.5.38"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071" checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
] ]
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.37" version = "4.5.38"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2" checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -392,9 +392,9 @@ dependencies = [
[[package]] [[package]]
name = "ctrlc" name = "ctrlc"
version = "3.4.6" version = "3.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "697b5419f348fd5ae2478e8018cb016c00a5881c7f46c717de98ffd135a5651c" checksum = "46f93780a459b7d656ef7f071fe699c4d3d2cb201c4b24d085b6ddc505276e73"
dependencies = [ dependencies = [
"nix", "nix",
"windows-sys", "windows-sys",
@ -465,9 +465,9 @@ checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.11" version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys", "windows-sys",
@ -508,9 +508,9 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@ -581,7 +581,7 @@ version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a"
dependencies = [ dependencies = [
"getrandom 0.3.2", "getrandom 0.3.3",
"libc", "libc",
] ]
@ -622,9 +622,9 @@ dependencies = [
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.13" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
@ -656,11 +656,11 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.29.0" version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.1",
"cfg-if", "cfg-if",
"cfg_aliases", "cfg_aliases",
"libc", "libc",
@ -715,6 +715,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]] [[package]]
name = "onig" name = "onig"
version = "6.4.0" version = "6.4.0"
@ -894,7 +900,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [ dependencies = [
"getrandom 0.3.2", "getrandom 0.3.3",
] ]
[[package]] [[package]]
@ -959,11 +965,11 @@ dependencies = [
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "1.0.5" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.1",
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
@ -1015,9 +1021,9 @@ dependencies = [
[[package]] [[package]]
name = "sha2" name = "sha2"
version = "0.10.8" version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures", "cpufeatures",
@ -1069,9 +1075,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.100" version = "2.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1085,7 +1091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
dependencies = [ dependencies = [
"fastrand", "fastrand",
"getrandom 0.3.2", "getrandom 0.3.3",
"once_cell", "once_cell",
"rustix", "rustix",
"windows-sys", "windows-sys",
@ -1490,9 +1496,9 @@ dependencies = [
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.61.0" version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [ dependencies = [
"windows-implement", "windows-implement",
"windows-interface", "windows-interface",
@ -1531,18 +1537,18 @@ checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
[[package]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.3.2" version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [ dependencies = [
"windows-link", "windows-link",
] ]
[[package]] [[package]]
name = "windows-strings" name = "windows-strings"
version = "0.4.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [ dependencies = [
"windows-link", "windows-link",
] ]
@ -1626,7 +1632,7 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.1",
] ]
[[package]] [[package]]
@ -1637,18 +1643,18 @@ checksum = "9b3a41ce106832b4da1c065baa4c31cf640cf965fa1483816402b7f6b96f0a64"
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.8.24" version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "zerocopy-derive"
version = "0.8.24" version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -10,7 +10,7 @@ use std::io::{self, BufWriter, IsTerminal, Read, Write};
#[cfg(unix)] #[cfg(unix)]
use std::net::Shutdown; use std::net::Shutdown;
#[cfg(unix)] #[cfg(unix)]
use std::os::fd::{AsFd, AsRawFd}; use std::os::fd::AsFd;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::FileTypeExt; use std::os::unix::fs::FileTypeExt;
#[cfg(unix)] #[cfg(unix)]
@ -372,7 +372,7 @@ fn cat_handle<R: FdReadable>(
#[cfg(unix)] #[cfg(unix)]
fn is_appending() -> bool { fn is_appending() -> bool {
let stdout = io::stdout(); let stdout = io::stdout();
let Ok(flags) = fcntl(stdout.as_raw_fd(), FcntlArg::F_GETFL) else { let Ok(flags) = fcntl(stdout.as_fd(), FcntlArg::F_GETFL) else {
return false; return false;
}; };
// TODO Replace `1 << 10` with `nix::fcntl::Oflag::O_APPEND`. // TODO Replace `1 << 10` with `nix::fcntl::Oflag::O_APPEND`.

View file

@ -5,10 +5,7 @@
use super::{CatResult, FdReadable, InputHandle}; use super::{CatResult, FdReadable, InputHandle};
use nix::unistd; use nix::unistd;
use std::os::{ use std::os::{fd::AsFd, unix::io::AsRawFd};
fd::AsFd,
unix::io::{AsRawFd, RawFd},
};
use uucore::pipes::{pipe, splice, splice_exact}; use uucore::pipes::{pipe, splice, splice_exact};
@ -41,7 +38,7 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
// we can recover by copying the data that we have from the // we can recover by copying the data that we have from the
// intermediate pipe to stdout using normal read/write. Then // intermediate pipe to stdout using normal read/write. Then
// we tell the caller to fall back. // we tell the caller to fall back.
copy_exact(pipe_rd.as_raw_fd(), write_fd, n)?; copy_exact(&pipe_rd, write_fd, n)?;
return Ok(true); return Ok(true);
} }
} }
@ -55,7 +52,7 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
/// Move exactly `num_bytes` bytes from `read_fd` to `write_fd`. /// Move exactly `num_bytes` bytes from `read_fd` to `write_fd`.
/// ///
/// Panics if not enough bytes can be read. /// Panics if not enough bytes can be read.
fn copy_exact(read_fd: RawFd, write_fd: &impl AsFd, num_bytes: usize) -> nix::Result<()> { fn copy_exact(read_fd: &impl AsFd, write_fd: &impl AsFd, num_bytes: usize) -> nix::Result<()> {
let mut left = num_bytes; let mut left = num_bytes;
let mut buf = [0; BUF_SIZE]; let mut buf = [0; BUF_SIZE];
while left > 0 { while left > 0 {

View file

@ -31,6 +31,8 @@ use std::ffi::OsString;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{self, Read, Seek, SeekFrom, Stdout, Write}; use std::io::{self, Read, Seek, SeekFrom, Stdout, Write};
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::fd::AsFd;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::OpenOptionsExt;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::{ use std::os::unix::{
@ -279,7 +281,7 @@ impl Source {
match self { match self {
Self::File(f) => { Self::File(f) => {
let advice = PosixFadviseAdvice::POSIX_FADV_DONTNEED; let advice = PosixFadviseAdvice::POSIX_FADV_DONTNEED;
posix_fadvise(f.as_raw_fd(), offset, len, advice) posix_fadvise(f.as_fd(), offset, len, advice)
} }
_ => Err(Errno::ESPIPE), // "Illegal seek" _ => Err(Errno::ESPIPE), // "Illegal seek"
} }
@ -649,7 +651,7 @@ impl Dest {
match self { match self {
Self::File(f, _) => { Self::File(f, _) => {
let advice = PosixFadviseAdvice::POSIX_FADV_DONTNEED; let advice = PosixFadviseAdvice::POSIX_FADV_DONTNEED;
posix_fadvise(f.as_raw_fd(), offset, len, advice) posix_fadvise(f.as_fd(), offset, len, advice)
} }
_ => Err(Errno::ESPIPE), // "Illegal seek" _ => Err(Errno::ESPIPE), // "Illegal seek"
} }
@ -784,7 +786,7 @@ impl<'a> Output<'a> {
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
if let Some(libc_flags) = make_linux_oflags(&settings.oflags) { if let Some(libc_flags) = make_linux_oflags(&settings.oflags) {
nix::fcntl::fcntl( nix::fcntl::fcntl(
fx.as_raw().as_raw_fd(), fx.as_raw().as_fd(),
F_SETFL(OFlag::from_bits_retain(libc_flags)), F_SETFL(OFlag::from_bits_retain(libc_flags)),
)?; )?;
} }

View file

@ -390,12 +390,12 @@ pub fn ensure_stdout_not_broken() -> Result<bool> {
poll::{PollFd, PollFlags, PollTimeout}, poll::{PollFd, PollFlags, PollTimeout},
sys::stat::{SFlag, fstat}, sys::stat::{SFlag, fstat},
}; };
use std::os::fd::{AsFd, AsRawFd}; use std::os::fd::AsFd;
let out = stdout(); let out = stdout();
// First, check that stdout is a fifo and return true if it's not the case // First, check that stdout is a fifo and return true if it's not the case
let stat = fstat(out.as_raw_fd())?; let stat = fstat(out.as_fd())?;
if !SFlag::from_bits_truncate(stat.st_mode).contains(SFlag::S_IFIFO) { if !SFlag::from_bits_truncate(stat.st_mode).contains(SFlag::S_IFIFO) {
return Ok(true); return Ok(true);
} }

View file

@ -18,7 +18,7 @@ use libc::{_SC_PAGESIZE, S_IFREG, sysconf};
use nix::sys::stat; use nix::sys::stat;
#[cfg(unix)] #[cfg(unix)]
use std::io::{Seek, SeekFrom}; use std::io::{Seek, SeekFrom};
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(unix)]
use std::os::fd::{AsFd, AsRawFd}; use std::os::fd::{AsFd, AsRawFd};
#[cfg(windows)] #[cfg(windows)]
use std::os::windows::fs::MetadataExt; use std::os::windows::fs::MetadataExt;
@ -48,9 +48,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
.write(true) .write(true)
.open("/dev/null") .open("/dev/null")
.map_err(|_| 0_usize)?; .map_err(|_| 0_usize)?;
let null_rdev = stat::fstat(null_file.as_raw_fd()) let null_rdev = stat::fstat(null_file.as_fd()).map_err(|_| 0_usize)?.st_rdev as libc::dev_t;
.map_err(|_| 0_usize)?
.st_rdev as libc::dev_t;
if (libc::major(null_rdev), libc::minor(null_rdev)) != (1, 3) { if (libc::major(null_rdev), libc::minor(null_rdev)) != (1, 3) {
// This is not a proper /dev/null, writing to it is probably bad // This is not a proper /dev/null, writing to it is probably bad
// Bit of an edge case, but it has been known to happen // Bit of an edge case, but it has been known to happen
@ -92,7 +90,7 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
#[cfg(unix)] #[cfg(unix)]
{ {
let fd = handle.as_raw_fd(); let fd = handle.as_fd();
if let Ok(stat) = stat::fstat(fd) { if let Ok(stat) = stat::fstat(fd) {
// If the file is regular, then the `st_size` should hold // If the file is regular, then the `st_size` should hold
// the file's size in bytes. // the file's size in bytes.
@ -132,7 +130,10 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
// However, the raw file descriptor in this situation would be equal to `0` // However, the raw file descriptor in this situation would be equal to `0`
// for STDIN in both invocations. // for STDIN in both invocations.
// Therefore we cannot rely of `st_size` here and should fall back on full read. // Therefore we cannot rely of `st_size` here and should fall back on full read.
if fd > 0 && (stat.st_mode as libc::mode_t & S_IFREG) != 0 && stat.st_size > 0 { if fd.as_raw_fd() > 0
&& (stat.st_mode as libc::mode_t & S_IFREG) != 0
&& stat.st_size > 0
{
let sys_page_size = unsafe { sysconf(_SC_PAGESIZE) as usize }; let sys_page_size = unsafe { sysconf(_SC_PAGESIZE) as usize };
if stat.st_size as usize % sys_page_size > 0 { if stat.st_size as usize % sys_page_size > 0 {
// regular file or file from /proc, /sys and similar pseudo-filesystems // regular file or file from /proc, /sys and similar pseudo-filesystems

View file

@ -37,9 +37,6 @@ mod tests {
}, },
}; };
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::fd::AsRawFd;
use std::io::{Read, Write}; use std::io::{Read, Write};
#[cfg(unix)] #[cfg(unix)]
@ -62,7 +59,7 @@ mod tests {
let n = pipe_write.write(data).unwrap(); let n = pipe_write.write(data).unwrap();
assert_eq!(n, data.len()); assert_eq!(n, data.len());
let mut buf = [0; 1024]; let mut buf = [0; 1024];
let n = copy_exact(pipe_read.as_raw_fd(), &pipe_write, data.len()).unwrap(); let n = copy_exact(&pipe_read, &pipe_write, data.len()).unwrap();
let n2 = pipe_read.read(&mut buf).unwrap(); let n2 = pipe_read.read(&mut buf).unwrap();
assert_eq!(n, n2); assert_eq!(n, n2);
assert_eq!(&buf[..n], data); assert_eq!(&buf[..n], data);

View file

@ -13,7 +13,7 @@ use crate::{
/// Buffer-based copying utilities for unix (excluding Linux). /// Buffer-based copying utilities for unix (excluding Linux).
use std::{ use std::{
io::{Read, Write}, io::{Read, Write},
os::fd::{AsFd, AsRawFd, RawFd}, os::fd::{AsFd, AsRawFd},
}; };
use super::common::Error; use super::common::Error;
@ -105,7 +105,7 @@ where
// we can recover by copying the data that we have from the // we can recover by copying the data that we have from the
// intermediate pipe to stdout using normal read/write. Then // intermediate pipe to stdout using normal read/write. Then
// we tell the caller to fall back. // we tell the caller to fall back.
copy_exact(pipe_rd.as_raw_fd(), dest, n)?; copy_exact(&pipe_rd, dest, n)?;
return Ok((bytes, true)); return Ok((bytes, true));
} }
@ -122,7 +122,7 @@ where
/// and `write` calls. /// and `write` calls.
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
pub(crate) fn copy_exact( pub(crate) fn copy_exact(
read_fd: RawFd, read_fd: &impl AsFd,
write_fd: &impl AsFd, write_fd: &impl AsFd,
num_bytes: usize, num_bytes: usize,
) -> std::io::Result<usize> { ) -> std::io::Result<usize> {

View file

@ -25,7 +25,9 @@ use std::hash::Hash;
use std::io::Stdin; use std::io::Stdin;
use std::io::{Error, ErrorKind, Result as IOResult}; use std::io::{Error, ErrorKind, Result as IOResult};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::{fs::MetadataExt, io::AsRawFd}; use std::os::fd::AsFd;
#[cfg(unix)]
use std::os::unix::fs::MetadataExt;
use std::path::{Component, MAIN_SEPARATOR, Path, PathBuf}; use std::path::{Component, MAIN_SEPARATOR, Path, PathBuf};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use winapi_util::AsHandleRef; use winapi_util::AsHandleRef;
@ -50,8 +52,8 @@ pub struct FileInformation(
impl FileInformation { impl FileInformation {
/// Get information from a currently open file /// Get information from a currently open file
#[cfg(unix)] #[cfg(unix)]
pub fn from_file(file: &impl AsRawFd) -> IOResult<Self> { pub fn from_file(file: &impl AsFd) -> IOResult<Self> {
let stat = nix::sys::stat::fstat(file.as_raw_fd())?; let stat = nix::sys::stat::fstat(file)?;
Ok(Self(stat)) Ok(Self(stat))
} }
@ -717,7 +719,7 @@ pub fn is_stdin_directory(stdin: &Stdin) -> bool {
#[cfg(unix)] #[cfg(unix)]
{ {
use nix::sys::stat::fstat; use nix::sys::stat::fstat;
let mode = fstat(stdin.as_raw_fd()).unwrap().st_mode as mode_t; let mode = fstat(stdin.as_fd()).unwrap().st_mode as mode_t;
has!(mode, S_IFDIR) has!(mode, S_IFDIR)
} }

View file

@ -19,8 +19,6 @@ use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
#[cfg(all(unix, feature = "chmod"))]
use std::os::unix::io::IntoRawFd;
use std::path::Path; use std::path::Path;
#[cfg(not(windows))] #[cfg(not(windows))]
use std::path::PathBuf; use std::path::PathBuf;
@ -544,50 +542,53 @@ fn test_ls_io_errors() {
#[cfg(unix)] #[cfg(unix)]
{ {
use std::os::fd::AsRawFd;
at.touch("some-dir4/bad-fd.txt"); at.touch("some-dir4/bad-fd.txt");
let fd1 = at.open("some-dir4/bad-fd.txt").into_raw_fd(); let fd1 = at.open("some-dir4/bad-fd.txt");
let fd2 = dup(dbg!(fd1)).unwrap(); let fd2 = dup(dbg!(&fd1)).unwrap();
close(fd1).unwrap(); close(fd1).unwrap();
// on the mac and in certain Linux containers bad fds are typed as dirs, // on the mac and in certain Linux containers bad fds are typed as dirs,
// however sometimes bad fds are typed as links and directory entry on links won't fail // however sometimes bad fds are typed as links and directory entry on links won't fail
if PathBuf::from(format!("/dev/fd/{fd2}")).is_dir() { if PathBuf::from(format!("/dev/fd/{}", fd2.as_raw_fd())).is_dir() {
scene scene
.ucmd() .ucmd()
.arg("-alR") .arg("-alR")
.arg(format!("/dev/fd/{fd2}")) .arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
.fails() .fails()
.stderr_contains(format!( .stderr_contains(format!(
"cannot open directory '/dev/fd/{fd2}': Bad file descriptor" "cannot open directory '/dev/fd/{}': Bad file descriptor",
fd2.as_raw_fd()
)) ))
.stdout_does_not_contain(format!("{fd2}:\n")); .stdout_does_not_contain(format!("{}:\n", fd2.as_raw_fd()));
scene scene
.ucmd() .ucmd()
.arg("-RiL") .arg("-RiL")
.arg(format!("/dev/fd/{fd2}")) .arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
.fails() .fails()
.stderr_contains(format!("cannot open directory '/dev/fd/{fd2}': Bad file descriptor")) .stderr_contains(format!("cannot open directory '/dev/fd/{}': Bad file descriptor", fd2.as_raw_fd()))
// don't double print bad fd errors // don't double print bad fd errors
.stderr_does_not_contain(format!("ls: cannot open directory '/dev/fd/{fd2}': Bad file descriptor\nls: cannot open directory '/dev/fd/{fd2}': Bad file descriptor")); .stderr_does_not_contain(format!("ls: cannot open directory '/dev/fd/{0}': Bad file descriptor\nls: cannot open directory '/dev/fd/{0}': Bad file descriptor", fd2.as_raw_fd()));
} else { } else {
scene scene
.ucmd() .ucmd()
.arg("-alR") .arg("-alR")
.arg(format!("/dev/fd/{fd2}")) .arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
.succeeds(); .succeeds();
scene scene
.ucmd() .ucmd()
.arg("-RiL") .arg("-RiL")
.arg(format!("/dev/fd/{fd2}")) .arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
.succeeds(); .succeeds();
} }
scene scene
.ucmd() .ucmd()
.arg("-alL") .arg("-alL")
.arg(format!("/dev/fd/{fd2}")) .arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
.succeeds(); .succeeds();
let _ = close(fd2); let _ = close(fd2);