From 184b2c8f1e55846bba72a1f0506bdaafab9a3264 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 23 May 2025 10:52:10 +0200 Subject: [PATCH] mesg: adapt to API changes in nix --- src/uu/mesg/Cargo.toml | 2 +- src/uu/mesg/src/mesg.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/uu/mesg/Cargo.toml b/src/uu/mesg/Cargo.toml index c75a4d8..382e99c 100644 --- a/src/uu/mesg/Cargo.toml +++ b/src/uu/mesg/Cargo.toml @@ -12,5 +12,5 @@ path = "src/main.rs" [dependencies] clap = { workspace = true } -nix = { workspace = true } +nix = { workspace = true, features = ["fs"] } uucore = { workspace = true } diff --git a/src/uu/mesg/src/mesg.rs b/src/uu/mesg/src/mesg.rs index 220ed36..4859581 100644 --- a/src/uu/mesg/src/mesg.rs +++ b/src/uu/mesg/src/mesg.rs @@ -5,7 +5,7 @@ use clap::{builder::PossibleValuesParser, crate_version, Arg, ArgAction, ArgMatches, Command}; #[cfg(target_family = "unix")] -use uucore::error::{set_exit_code, UIoError}; +use uucore::error::{set_exit_code, UIoError, USimpleError}; use uucore::{error::UResult, format_usage, help_about, help_usage}; const ABOUT: &str = help_about!("mesg.md"); @@ -14,7 +14,7 @@ const USAGE: &str = help_usage!("mesg.md"); #[cfg(target_family = "unix")] pub fn do_mesg(matches: &ArgMatches) -> UResult<()> { use nix::sys::stat::{fchmod, fstat, Mode}; - use std::{io, os::fd::AsRawFd}; + use std::io; use std::{io::IsTerminal, os::fd::AsFd}; for fd in &[ @@ -23,7 +23,7 @@ pub fn do_mesg(matches: &ArgMatches) -> UResult<()> { std::io::stderr().as_fd(), ] { if fd.is_terminal() { - let st = fstat(fd.as_raw_fd())?; + let st = fstat(fd.as_fd()).map_err(|e| USimpleError::new(1, e.desc()))?; if let Some(enable) = matches.get_one::("enable") { // 'mesg y' on the GNU version seems to only modify the group write bit, // but 'mesg n' modifies both group and others write bits. @@ -32,7 +32,8 @@ pub fn do_mesg(matches: &ArgMatches) -> UResult<()> { } else { st.st_mode & !0o022 }; - fchmod(fd.as_raw_fd(), Mode::from_bits_retain(new_mode))?; + fchmod(fd.as_fd(), Mode::from_bits_retain(new_mode)) + .map_err(|e| USimpleError::new(1, e.desc()))?; if enable == "n" { set_exit_code(1); }