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:
commit
aa5dd0e3d0
12 changed files with 99 additions and 93 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -766,9 +766,9 @@ checksum = "4f211af61d8efdd104f96e57adf5e426ba1bc3ed7a4ead616e15e5881fd79c4d"
|
|||
|
||||
[[package]]
|
||||
name = "ctrlc"
|
||||
version = "3.4.6"
|
||||
version = "3.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "697b5419f348fd5ae2478e8018cb016c00a5881c7f46c717de98ffd135a5651c"
|
||||
checksum = "46f93780a459b7d656ef7f071fe699c4d3d2cb201c4b24d085b6ddc505276e73"
|
||||
dependencies = [
|
||||
"nix",
|
||||
"windows-sys 0.59.0",
|
||||
|
@ -1472,9 +1472,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.29.0"
|
||||
version = "0.30.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||
dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
"cfg-if",
|
||||
|
|
|
@ -289,7 +289,7 @@ clap_mangen = "0.2"
|
|||
compare = "0.1.0"
|
||||
coz = { version = "0.1.3" }
|
||||
crossterm = "0.29.0"
|
||||
ctrlc = { version = "3.4.4", features = ["termination"] }
|
||||
ctrlc = { version = "3.4.7", features = ["termination"] }
|
||||
dns-lookup = { version = "2.0.4" }
|
||||
exacl = "0.12.0"
|
||||
file_diff = "1.0.0"
|
||||
|
@ -311,7 +311,7 @@ lscolors = { version = "0.20.0", default-features = false, features = [
|
|||
] }
|
||||
memchr = "2.7.2"
|
||||
memmap2 = "0.9.4"
|
||||
nix = { version = "0.29", default-features = false }
|
||||
nix = { version = "0.30", default-features = false }
|
||||
nom = "8.0.0"
|
||||
notify = { version = "=8.0.0", features = ["macos_kqueue"] }
|
||||
num-bigint = "0.4.4"
|
||||
|
|
92
fuzz/Cargo.lock
generated
92
fuzz/Cargo.lock
generated
|
@ -67,12 +67,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.7"
|
||||
version = "3.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
|
||||
checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
|
@ -130,9 +130,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.0"
|
||||
version = "2.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||
|
||||
[[package]]
|
||||
name = "blake2b_simd"
|
||||
|
@ -192,9 +192,9 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.20"
|
||||
version = "1.2.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a"
|
||||
checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
|
@ -248,18 +248,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.37"
|
||||
version = "4.5.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
|
||||
checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.37"
|
||||
version = "4.5.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
|
||||
checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
@ -392,9 +392,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ctrlc"
|
||||
version = "3.4.6"
|
||||
version = "3.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "697b5419f348fd5ae2478e8018cb016c00a5881c7f46c717de98ffd135a5651c"
|
||||
checksum = "46f93780a459b7d656ef7f071fe699c4d3d2cb201c4b24d085b6ddc505276e73"
|
||||
dependencies = [
|
||||
"nix",
|
||||
"windows-sys",
|
||||
|
@ -465,9 +465,9 @@ checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
|||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.11"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
|
||||
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
|
@ -508,9 +508,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
|
@ -581,7 +581,7 @@ version = "0.1.33"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a"
|
||||
dependencies = [
|
||||
"getrandom 0.3.2",
|
||||
"getrandom 0.3.3",
|
||||
"libc",
|
||||
]
|
||||
|
||||
|
@ -622,9 +622,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
version = "0.2.13"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72"
|
||||
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
|
@ -656,11 +656,11 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
|||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.29.0"
|
||||
version = "0.30.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||
dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
"bitflags 2.9.1",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
|
@ -715,6 +715,12 @@ version = "1.21.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||
|
||||
[[package]]
|
||||
name = "onig"
|
||||
version = "6.4.0"
|
||||
|
@ -894,7 +900,7 @@ version = "0.9.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom 0.3.2",
|
||||
"getrandom 0.3.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -959,11 +965,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.0.5"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
|
||||
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
|
||||
dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
"bitflags 2.9.1",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
|
@ -1015,9 +1021,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
|
@ -1069,9 +1075,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
version = "2.0.101"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1085,7 +1091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.2",
|
||||
"getrandom 0.3.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
|
@ -1490,9 +1496,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.61.0"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980"
|
||||
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
|
@ -1531,18 +1537,18 @@ checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
|
|||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.2"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252"
|
||||
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.4.0"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97"
|
||||
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
@ -1626,7 +1632,7 @@ version = "0.39.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||
dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
"bitflags 2.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1637,18 +1643,18 @@ checksum = "9b3a41ce106832b4da1c065baa4c31cf640cf965fa1483816402b7f6b96f0a64"
|
|||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.24"
|
||||
version = "0.8.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
|
||||
checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.24"
|
||||
version = "0.8.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
|
||||
checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::io::{self, BufWriter, IsTerminal, Read, Write};
|
|||
#[cfg(unix)]
|
||||
use std::net::Shutdown;
|
||||
#[cfg(unix)]
|
||||
use std::os::fd::{AsFd, AsRawFd};
|
||||
use std::os::fd::AsFd;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
#[cfg(unix)]
|
||||
|
@ -372,7 +372,7 @@ fn cat_handle<R: FdReadable>(
|
|||
#[cfg(unix)]
|
||||
fn is_appending() -> bool {
|
||||
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;
|
||||
};
|
||||
// TODO Replace `1 << 10` with `nix::fcntl::Oflag::O_APPEND`.
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
use super::{CatResult, FdReadable, InputHandle};
|
||||
|
||||
use nix::unistd;
|
||||
use std::os::{
|
||||
fd::AsFd,
|
||||
unix::io::{AsRawFd, RawFd},
|
||||
};
|
||||
use std::os::{fd::AsFd, unix::io::AsRawFd};
|
||||
|
||||
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
|
||||
// intermediate pipe to stdout using normal read/write. Then
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -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`.
|
||||
///
|
||||
/// 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 buf = [0; BUF_SIZE];
|
||||
while left > 0 {
|
||||
|
|
|
@ -31,6 +31,8 @@ use std::ffi::OsString;
|
|||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Read, Seek, SeekFrom, Stdout, Write};
|
||||
#[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;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::{
|
||||
|
@ -279,7 +281,7 @@ impl Source {
|
|||
match self {
|
||||
Self::File(f) => {
|
||||
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"
|
||||
}
|
||||
|
@ -649,7 +651,7 @@ impl Dest {
|
|||
match self {
|
||||
Self::File(f, _) => {
|
||||
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"
|
||||
}
|
||||
|
@ -784,7 +786,7 @@ impl<'a> Output<'a> {
|
|||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
if let Some(libc_flags) = make_linux_oflags(&settings.oflags) {
|
||||
nix::fcntl::fcntl(
|
||||
fx.as_raw().as_raw_fd(),
|
||||
fx.as_raw().as_fd(),
|
||||
F_SETFL(OFlag::from_bits_retain(libc_flags)),
|
||||
)?;
|
||||
}
|
||||
|
|
|
@ -390,12 +390,12 @@ pub fn ensure_stdout_not_broken() -> Result<bool> {
|
|||
poll::{PollFd, PollFlags, PollTimeout},
|
||||
sys::stat::{SFlag, fstat},
|
||||
};
|
||||
use std::os::fd::{AsFd, AsRawFd};
|
||||
use std::os::fd::AsFd;
|
||||
|
||||
let out = stdout();
|
||||
|
||||
// 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) {
|
||||
return Ok(true);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use libc::{_SC_PAGESIZE, S_IFREG, sysconf};
|
|||
use nix::sys::stat;
|
||||
#[cfg(unix)]
|
||||
use std::io::{Seek, SeekFrom};
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[cfg(unix)]
|
||||
use std::os::fd::{AsFd, AsRawFd};
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
|
@ -48,9 +48,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
|
|||
.write(true)
|
||||
.open("/dev/null")
|
||||
.map_err(|_| 0_usize)?;
|
||||
let null_rdev = stat::fstat(null_file.as_raw_fd())
|
||||
.map_err(|_| 0_usize)?
|
||||
.st_rdev as libc::dev_t;
|
||||
let null_rdev = stat::fstat(null_file.as_fd()).map_err(|_| 0_usize)?.st_rdev as libc::dev_t;
|
||||
if (libc::major(null_rdev), libc::minor(null_rdev)) != (1, 3) {
|
||||
// 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
|
||||
|
@ -92,7 +90,7 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
|
|||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let fd = handle.as_raw_fd();
|
||||
let fd = handle.as_fd();
|
||||
if let Ok(stat) = stat::fstat(fd) {
|
||||
// If the file is regular, then the `st_size` should hold
|
||||
// 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`
|
||||
// for STDIN in both invocations.
|
||||
// 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 };
|
||||
if stat.st_size as usize % sys_page_size > 0 {
|
||||
// regular file or file from /proc, /sys and similar pseudo-filesystems
|
||||
|
|
|
@ -37,9 +37,6 @@ mod tests {
|
|||
},
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::os::fd::AsRawFd;
|
||||
|
||||
use std::io::{Read, Write};
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -62,7 +59,7 @@ mod tests {
|
|||
let n = pipe_write.write(data).unwrap();
|
||||
assert_eq!(n, data.len());
|
||||
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();
|
||||
assert_eq!(n, n2);
|
||||
assert_eq!(&buf[..n], data);
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
/// Buffer-based copying utilities for unix (excluding Linux).
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
os::fd::{AsFd, AsRawFd, RawFd},
|
||||
os::fd::{AsFd, AsRawFd},
|
||||
};
|
||||
|
||||
use super::common::Error;
|
||||
|
@ -105,7 +105,7 @@ where
|
|||
// we can recover by copying the data that we have from the
|
||||
// intermediate pipe to stdout using normal read/write. Then
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ where
|
|||
/// and `write` calls.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub(crate) fn copy_exact(
|
||||
read_fd: RawFd,
|
||||
read_fd: &impl AsFd,
|
||||
write_fd: &impl AsFd,
|
||||
num_bytes: usize,
|
||||
) -> std::io::Result<usize> {
|
||||
|
|
|
@ -25,7 +25,9 @@ use std::hash::Hash;
|
|||
use std::io::Stdin;
|
||||
use std::io::{Error, ErrorKind, Result as IOResult};
|
||||
#[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};
|
||||
#[cfg(target_os = "windows")]
|
||||
use winapi_util::AsHandleRef;
|
||||
|
@ -50,8 +52,8 @@ pub struct FileInformation(
|
|||
impl FileInformation {
|
||||
/// Get information from a currently open file
|
||||
#[cfg(unix)]
|
||||
pub fn from_file(file: &impl AsRawFd) -> IOResult<Self> {
|
||||
let stat = nix::sys::stat::fstat(file.as_raw_fd())?;
|
||||
pub fn from_file(file: &impl AsFd) -> IOResult<Self> {
|
||||
let stat = nix::sys::stat::fstat(file)?;
|
||||
Ok(Self(stat))
|
||||
}
|
||||
|
||||
|
@ -717,7 +719,7 @@ pub fn is_stdin_directory(stdin: &Stdin) -> bool {
|
|||
#[cfg(unix)]
|
||||
{
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@ use std::collections::HashMap;
|
|||
use std::ffi::OsStr;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
#[cfg(all(unix, feature = "chmod"))]
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::path::Path;
|
||||
#[cfg(not(windows))]
|
||||
use std::path::PathBuf;
|
||||
|
@ -544,50 +542,53 @@ fn test_ls_io_errors() {
|
|||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::fd::AsRawFd;
|
||||
|
||||
at.touch("some-dir4/bad-fd.txt");
|
||||
let fd1 = at.open("some-dir4/bad-fd.txt").into_raw_fd();
|
||||
let fd2 = dup(dbg!(fd1)).unwrap();
|
||||
let fd1 = at.open("some-dir4/bad-fd.txt");
|
||||
let fd2 = dup(dbg!(&fd1)).unwrap();
|
||||
close(fd1).unwrap();
|
||||
|
||||
// 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
|
||||
if PathBuf::from(format!("/dev/fd/{fd2}")).is_dir() {
|
||||
if PathBuf::from(format!("/dev/fd/{}", fd2.as_raw_fd())).is_dir() {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-alR")
|
||||
.arg(format!("/dev/fd/{fd2}"))
|
||||
.arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
|
||||
.fails()
|
||||
.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
|
||||
.ucmd()
|
||||
.arg("-RiL")
|
||||
.arg(format!("/dev/fd/{fd2}"))
|
||||
.arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
|
||||
.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
|
||||
.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 {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-alR")
|
||||
.arg(format!("/dev/fd/{fd2}"))
|
||||
.arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
|
||||
.succeeds();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-RiL")
|
||||
.arg(format!("/dev/fd/{fd2}"))
|
||||
.arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
|
||||
.succeeds();
|
||||
}
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-alL")
|
||||
.arg(format!("/dev/fd/{fd2}"))
|
||||
.arg(format!("/dev/fd/{}", fd2.as_raw_fd()))
|
||||
.succeeds();
|
||||
|
||||
let _ = close(fd2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue