Skip to content

Commit

Permalink
Merge pull request uutils#6648 from cakebaker/bump_nix_and_ctrlc
Browse files Browse the repository at this point in the history
Bump `nix` & `ctrlc` and adapt code to API changes in `nix`
  • Loading branch information
sylvestre committed Aug 21, 2024
2 parents 12e2cc3 + 5db3b47 commit 72473f7
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 36 deletions.
25 changes: 17 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ lscolors = { version = "0.19.0", default-features = false, features = [
] }
memchr = "2.7.2"
memmap2 = "0.9.4"
nix = { version = "0.28", default-features = false }
nix = { version = "0.29", default-features = false }
nom = "7.1.3"
notify = { version = "=6.0.1", features = ["macos_kqueue"] }
num-bigint = "0.4.4"
Expand Down
2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ skip = [
{ name = "windows-sys", version = "0.45.0" },
# various crates
{ name = "windows-sys", version = "0.48.0" },
# various crates
{ name = "windows-sys", version = "0.52.0" },
# windows-sys
{ name = "windows-targets", version = "0.42.2" },
# windows-sys
Expand Down
6 changes: 3 additions & 3 deletions src/uu/cat/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use uucore::error::UResult;
use uucore::fs::FileInformation;

#[cfg(unix)]
use std::os::unix::io::AsRawFd;
use std::os::fd::{AsFd, AsRawFd};

/// Linux splice support
#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -125,12 +125,12 @@ struct OutputState {
}

#[cfg(unix)]
trait FdReadable: Read + AsRawFd {}
trait FdReadable: Read + AsFd + AsRawFd {}
#[cfg(not(unix))]
trait FdReadable: Read {}

#[cfg(unix)]
impl<T> FdReadable for T where T: Read + AsRawFd {}
impl<T> FdReadable for T where T: Read + AsFd + AsRawFd {}
#[cfg(not(unix))]
impl<T> FdReadable for T where T: Read {}

Expand Down
4 changes: 2 additions & 2 deletions src/uu/wc/src/count_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use nix::sys::stat;
#[cfg(unix)]
use std::io::{Seek, SeekFrom};
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::io::AsRawFd;
use std::os::fd::{AsFd, AsRawFd};
#[cfg(windows)]
use std::os::windows::fs::MetadataExt;
#[cfg(windows)]
Expand All @@ -43,7 +43,7 @@ const SPLICE_SIZE: usize = 128 * 1024;
/// caller will fall back to a simpler method.
#[inline]
#[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()
.write(true)
.open("/dev/null")
Expand Down
4 changes: 2 additions & 2 deletions src/uu/wc/src/countable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use std::fs::File;
use std::io::{BufRead, BufReader, Read, StdinLock};

#[cfg(unix)]
use std::os::unix::io::AsRawFd;
use std::os::fd::{AsFd, AsRawFd};

#[cfg(unix)]
pub trait WordCountable: AsRawFd + Read {
pub trait WordCountable: AsFd + AsRawFd + Read {
type Buffered: BufRead;
fn buffered(self) -> Self::Buffered;
fn inner_file(&mut self) -> Option<&mut File>;
Expand Down
10 changes: 8 additions & 2 deletions src/uu/yes/src/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
//! make any effort to rescue data from the pipe if splice() fails, we can
//! 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 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;

if is_pipe {
Expand Down
4 changes: 3 additions & 1 deletion src/uu/yes/src/yes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command};
use std::error::Error;
use std::ffi::OsString;
use std::io::{self, Write};
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::fd::AsFd;
use uucore::error::{UResult, USimpleError};
#[cfg(unix)]
use uucore::signals::enable_pipe_errors;
Expand Down Expand Up @@ -118,7 +120,7 @@ pub fn exec(bytes: &[u8]) -> io::Result<()> {

#[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(()),
Err(splice::Error::Io(err)) => return Err(err),
Err(splice::Error::Unsupported) => (),
Expand Down
23 changes: 6 additions & 17 deletions src/uucore/src/lib/features/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fs::File;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::io::IoSlice;
#[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"))]
use nix::fcntl::SpliceFFlags;
Expand All @@ -35,15 +35,8 @@ pub fn pipe() -> Result<(File, File)> {
/// a [`pipe`] and then from the pipe into your target (with `splice_exact`):
/// this is still very efficient.
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn splice(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Result<usize> {
nix::fcntl::splice(
source.as_raw_fd(),
None,
target.as_raw_fd(),
None,
len,
SpliceFFlags::empty(),
)
pub fn splice(source: &impl AsFd, target: &impl AsFd, len: usize) -> Result<usize> {
nix::fcntl::splice(source, None, target, None, len, SpliceFFlags::empty())
}

/// Splice wrapper which fully finishes the write.
Expand All @@ -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.
#[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;
while left != 0 {
let written = splice(source, target, left)?;
Expand All @@ -66,10 +59,6 @@ pub fn splice_exact(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) ->
///
/// Returns the number of successfully copied bytes.
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn vmsplice(target: &impl AsRawFd, bytes: &[u8]) -> Result<usize> {
nix::fcntl::vmsplice(
target.as_raw_fd(),
&[IoSlice::new(bytes)],
SpliceFFlags::empty(),
)
pub fn vmsplice(target: &impl AsFd, bytes: &[u8]) -> Result<usize> {
nix::fcntl::vmsplice(target, &[IoSlice::new(bytes)], SpliceFFlags::empty())
}

0 comments on commit 72473f7

Please sign in to comment.