mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #6648 from cakebaker/bump_nix_and_ctrlc
Bump `nix` & `ctrlc` and adapt code to API changes in `nix`
This commit is contained in:
commit
72473f73bc
9 changed files with 44 additions and 36 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
@ -300,9 +300,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg_aliases"
|
name = "cfg_aliases"
|
||||||
version = "0.1.1"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
|
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
|
@ -733,12 +733,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ctrlc"
|
name = "ctrlc"
|
||||||
version = "3.4.4"
|
version = "3.4.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "672465ae37dc1bc6380a6547a8883d5dd397b0f1faaad4f265726cc7042a5345"
|
checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nix",
|
"nix",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1448,9 +1448,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.28.0"
|
version = "0.29.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4"
|
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
@ -3661,7 +3661,7 @@ version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3716,6 +3716,15 @@ dependencies = [
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.42.2"
|
version = "0.42.2"
|
||||||
|
|
|
@ -303,7 +303,7 @@ lscolors = { version = "0.19.0", default-features = false, features = [
|
||||||
] }
|
] }
|
||||||
memchr = "2.7.2"
|
memchr = "2.7.2"
|
||||||
memmap2 = "0.9.4"
|
memmap2 = "0.9.4"
|
||||||
nix = { version = "0.28", default-features = false }
|
nix = { version = "0.29", default-features = false }
|
||||||
nom = "7.1.3"
|
nom = "7.1.3"
|
||||||
notify = { version = "=6.0.1", features = ["macos_kqueue"] }
|
notify = { version = "=6.0.1", features = ["macos_kqueue"] }
|
||||||
num-bigint = "0.4.4"
|
num-bigint = "0.4.4"
|
||||||
|
|
|
@ -62,6 +62,8 @@ skip = [
|
||||||
{ name = "windows-sys", version = "0.45.0" },
|
{ name = "windows-sys", version = "0.45.0" },
|
||||||
# various crates
|
# various crates
|
||||||
{ name = "windows-sys", version = "0.48.0" },
|
{ name = "windows-sys", version = "0.48.0" },
|
||||||
|
# various crates
|
||||||
|
{ name = "windows-sys", version = "0.52.0" },
|
||||||
# windows-sys
|
# windows-sys
|
||||||
{ name = "windows-targets", version = "0.42.2" },
|
{ name = "windows-targets", version = "0.42.2" },
|
||||||
# windows-sys
|
# windows-sys
|
||||||
|
|
|
@ -13,7 +13,7 @@ use uucore::error::UResult;
|
||||||
use uucore::fs::FileInformation;
|
use uucore::fs::FileInformation;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::fd::{AsFd, AsRawFd};
|
||||||
|
|
||||||
/// Linux splice support
|
/// Linux splice support
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
@ -125,12 +125,12 @@ struct OutputState {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
trait FdReadable: Read + AsRawFd {}
|
trait FdReadable: Read + AsFd + AsRawFd {}
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
trait FdReadable: Read {}
|
trait FdReadable: Read {}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl<T> FdReadable for T where T: Read + AsRawFd {}
|
impl<T> FdReadable for T where T: Read + AsFd + AsRawFd {}
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
impl<T> FdReadable for T where T: Read {}
|
impl<T> FdReadable for T where T: Read {}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ 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(any(target_os = "linux", target_os = "android"))]
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::fd::{AsFd, AsRawFd};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::os::windows::fs::MetadataExt;
|
use std::os::windows::fs::MetadataExt;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -43,7 +43,7 @@ const SPLICE_SIZE: usize = 128 * 1024;
|
||||||
/// caller will fall back to a simpler method.
|
/// caller will fall back to a simpler method.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
fn count_bytes_using_splice(fd: &impl AsRawFd) -> Result<usize, usize> {
|
fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
|
||||||
let null_file = OpenOptions::new()
|
let null_file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.open("/dev/null")
|
.open("/dev/null")
|
||||||
|
|
|
@ -11,10 +11,10 @@ use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, StdinLock};
|
use std::io::{BufRead, BufReader, Read, StdinLock};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::fd::{AsFd, AsRawFd};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub trait WordCountable: AsRawFd + Read {
|
pub trait WordCountable: AsFd + AsRawFd + Read {
|
||||||
type Buffered: BufRead;
|
type Buffered: BufRead;
|
||||||
fn buffered(self) -> Self::Buffered;
|
fn buffered(self) -> Self::Buffered;
|
||||||
fn inner_file(&mut self) -> Option<&mut File>;
|
fn inner_file(&mut self) -> Option<&mut File>;
|
||||||
|
|
|
@ -20,13 +20,19 @@
|
||||||
//! make any effort to rescue data from the pipe if splice() fails, we can
|
//! make any effort to rescue data from the pipe if splice() fails, we can
|
||||||
//! just fall back and start over from the beginning.
|
//! just fall back and start over from the beginning.
|
||||||
|
|
||||||
use std::{io, os::unix::io::AsRawFd};
|
use std::{
|
||||||
|
io,
|
||||||
|
os::fd::{AsFd, AsRawFd},
|
||||||
|
};
|
||||||
|
|
||||||
use nix::{errno::Errno, libc::S_IFIFO, sys::stat::fstat};
|
use nix::{errno::Errno, libc::S_IFIFO, sys::stat::fstat};
|
||||||
|
|
||||||
use uucore::pipes::{pipe, splice_exact, vmsplice};
|
use uucore::pipes::{pipe, splice_exact, vmsplice};
|
||||||
|
|
||||||
pub(crate) fn splice_data(bytes: &[u8], out: &impl AsRawFd) -> Result<()> {
|
pub(crate) fn splice_data<T>(bytes: &[u8], out: &T) -> Result<()>
|
||||||
|
where
|
||||||
|
T: AsRawFd + AsFd,
|
||||||
|
{
|
||||||
let is_pipe = fstat(out.as_raw_fd())?.st_mode as nix::libc::mode_t & S_IFIFO != 0;
|
let is_pipe = fstat(out.as_raw_fd())?.st_mode as nix::libc::mode_t & S_IFIFO != 0;
|
||||||
|
|
||||||
if is_pipe {
|
if is_pipe {
|
||||||
|
|
|
@ -9,6 +9,8 @@ use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
use std::os::fd::AsFd;
|
||||||
use uucore::error::{UResult, USimpleError};
|
use uucore::error::{UResult, USimpleError};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use uucore::signals::enable_pipe_errors;
|
use uucore::signals::enable_pipe_errors;
|
||||||
|
@ -118,7 +120,7 @@ pub fn exec(bytes: &[u8]) -> io::Result<()> {
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
{
|
{
|
||||||
match splice::splice_data(bytes, &stdout) {
|
match splice::splice_data(bytes, &stdout.as_fd()) {
|
||||||
Ok(_) => return Ok(()),
|
Ok(_) => return Ok(()),
|
||||||
Err(splice::Error::Io(err)) => return Err(err),
|
Err(splice::Error::Io(err)) => return Err(err),
|
||||||
Err(splice::Error::Unsupported) => (),
|
Err(splice::Error::Unsupported) => (),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::fs::File;
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use std::io::IoSlice;
|
use std::io::IoSlice;
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::fd::AsFd;
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use nix::fcntl::SpliceFFlags;
|
use nix::fcntl::SpliceFFlags;
|
||||||
|
@ -35,15 +35,8 @@ pub fn pipe() -> Result<(File, File)> {
|
||||||
/// a [`pipe`] and then from the pipe into your target (with `splice_exact`):
|
/// a [`pipe`] and then from the pipe into your target (with `splice_exact`):
|
||||||
/// this is still very efficient.
|
/// this is still very efficient.
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub fn splice(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Result<usize> {
|
pub fn splice(source: &impl AsFd, target: &impl AsFd, len: usize) -> Result<usize> {
|
||||||
nix::fcntl::splice(
|
nix::fcntl::splice(source, None, target, None, len, SpliceFFlags::empty())
|
||||||
source.as_raw_fd(),
|
|
||||||
None,
|
|
||||||
target.as_raw_fd(),
|
|
||||||
None,
|
|
||||||
len,
|
|
||||||
SpliceFFlags::empty(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Splice wrapper which fully finishes the write.
|
/// Splice wrapper which fully finishes the write.
|
||||||
|
@ -52,7 +45,7 @@ pub fn splice(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Resul
|
||||||
///
|
///
|
||||||
/// Panics if `source` runs out of data before `len` bytes have been moved.
|
/// Panics if `source` runs out of data before `len` bytes have been moved.
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub fn splice_exact(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Result<()> {
|
pub fn splice_exact(source: &impl AsFd, target: &impl AsFd, len: usize) -> Result<()> {
|
||||||
let mut left = len;
|
let mut left = len;
|
||||||
while left != 0 {
|
while left != 0 {
|
||||||
let written = splice(source, target, left)?;
|
let written = splice(source, target, left)?;
|
||||||
|
@ -66,10 +59,6 @@ pub fn splice_exact(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) ->
|
||||||
///
|
///
|
||||||
/// Returns the number of successfully copied bytes.
|
/// Returns the number of successfully copied bytes.
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub fn vmsplice(target: &impl AsRawFd, bytes: &[u8]) -> Result<usize> {
|
pub fn vmsplice(target: &impl AsFd, bytes: &[u8]) -> Result<usize> {
|
||||||
nix::fcntl::vmsplice(
|
nix::fcntl::vmsplice(target, &[IoSlice::new(bytes)], SpliceFFlags::empty())
|
||||||
target.as_raw_fd(),
|
|
||||||
&[IoSlice::new(bytes)],
|
|
||||||
SpliceFFlags::empty(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue