5
5
6
6
use clap:: { builder:: PossibleValuesParser , crate_version, Arg , ArgAction , ArgMatches , Command } ;
7
7
#[ cfg( target_family = "unix" ) ]
8
- use uucore:: error:: { set_exit_code, UIoError } ;
8
+ use uucore:: error:: { set_exit_code, UIoError , USimpleError } ;
9
9
use uucore:: { error:: UResult , format_usage, help_about, help_usage} ;
10
10
11
11
const ABOUT : & str = help_about ! ( "mesg.md" ) ;
@@ -14,7 +14,7 @@ const USAGE: &str = help_usage!("mesg.md");
14
14
#[ cfg( target_family = "unix" ) ]
15
15
pub fn do_mesg ( matches : & ArgMatches ) -> UResult < ( ) > {
16
16
use nix:: sys:: stat:: { fchmod, fstat, Mode } ;
17
- use std:: { io , os :: fd :: AsRawFd } ;
17
+ use std:: io ;
18
18
use std:: { io:: IsTerminal , os:: fd:: AsFd } ;
19
19
20
20
for fd in & [
@@ -23,7 +23,7 @@ pub fn do_mesg(matches: &ArgMatches) -> UResult<()> {
23
23
std:: io:: stderr ( ) . as_fd ( ) ,
24
24
] {
25
25
if fd. is_terminal ( ) {
26
- let st = fstat ( fd. as_raw_fd ( ) ) ?;
26
+ let st = fstat ( fd. as_fd ( ) ) . map_err ( |e| USimpleError :: new ( 1 , e . desc ( ) ) ) ?;
27
27
if let Some ( enable) = matches. get_one :: < String > ( "enable" ) {
28
28
// 'mesg y' on the GNU version seems to only modify the group write bit,
29
29
// but 'mesg n' modifies both group and others write bits.
@@ -32,7 +32,8 @@ pub fn do_mesg(matches: &ArgMatches) -> UResult<()> {
32
32
} else {
33
33
st. st_mode & !0o022
34
34
} ;
35
- fchmod ( fd. as_raw_fd ( ) , Mode :: from_bits_retain ( new_mode) ) ?;
35
+ fchmod ( fd. as_fd ( ) , Mode :: from_bits_retain ( new_mode) )
36
+ . map_err ( |e| USimpleError :: new ( 1 , e. desc ( ) ) ) ?;
36
37
if enable == "n" {
37
38
set_exit_code ( 1 ) ;
38
39
}
0 commit comments