Skip to content

Commit e471840

Browse files
committed
refactor: avoid std::io::Error imports
1 parent ba6d437 commit e471840

18 files changed

Lines changed: 65 additions & 65 deletions

File tree

src/uu/chroot/src/chroot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod error;
99
use crate::error::ChrootError;
1010
use clap::{Arg, ArgAction, Command};
1111
use std::ffi::OsStr;
12-
use std::io::{Error, ErrorKind};
12+
use std::io::ErrorKind;
1313
use std::os::unix::process::CommandExt;
1414
use std::path::{Path, PathBuf};
1515
use std::process;
@@ -317,7 +317,7 @@ fn set_supplemental_gids(gids: &[libc::gid_t]) -> std::io::Result<()> {
317317
if err == 0 {
318318
Ok(())
319319
} else {
320-
Err(Error::last_os_error())
320+
Err(std::io::Error::last_os_error())
321321
}
322322
}
323323

@@ -327,7 +327,7 @@ fn set_gid(gid: libc::gid_t) -> std::io::Result<()> {
327327
if err == 0 {
328328
Ok(())
329329
} else {
330-
Err(Error::last_os_error())
330+
Err(std::io::Error::last_os_error())
331331
}
332332
}
333333

@@ -337,7 +337,7 @@ fn set_uid(uid: libc::uid_t) -> std::io::Result<()> {
337337
if err == 0 {
338338
Ok(())
339339
} else {
340-
Err(Error::last_os_error())
340+
Err(std::io::Error::last_os_error())
341341
}
342342
}
343343

src/uu/chroot/src/error.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// spell-checker:ignore NEWROOT Userspec userspec
66
//! Errors returned by chroot.
77
use std::ffi::OsString;
8-
use std::io::Error;
98
use std::path::PathBuf;
109
use uucore::display::Quotable;
1110
use uucore::error::UError;
@@ -17,15 +16,15 @@ use uucore::translate;
1716
pub enum ChrootError {
1817
/// Failed to enter the specified directory.
1918
#[error("{}", translate!("chroot-error-cannot-enter", "dir" => _0.quote(), "err" => _1))]
20-
CannotEnter(PathBuf, #[source] Error),
19+
CannotEnter(PathBuf, #[source] std::io::Error),
2120

2221
/// Failed to execute the specified command.
2322
#[error("{}", translate!("chroot-error-command-failed", "cmd" => _0.quote(), "err" => _1))]
24-
CommandFailed(OsString, #[source] Error),
23+
CommandFailed(OsString, #[source] std::io::Error),
2524

2625
/// Failed to find the specified command.
2726
#[error("{}", translate!("chroot-error-command-not-found", "cmd" => _0.quote(), "err" => _1))]
28-
CommandNotFound(OsString, #[source] Error),
27+
CommandNotFound(OsString, #[source] std::io::Error),
2928

3029
#[error("{}", translate!("chroot-error-groups-parsing-failed"))]
3130
GroupsParsingFailed,
@@ -57,15 +56,15 @@ pub enum ChrootError {
5756

5857
/// The call to `setgid()` failed.
5958
#[error("{}", translate!("chroot-error-set-gid-failed", "gid" => _0, "err" => _1))]
60-
SetGidFailed(String, #[source] Error),
59+
SetGidFailed(String, #[source] std::io::Error),
6160

6261
/// The call to `setgroups()` failed.
6362
#[error("{}", translate!("chroot-error-set-groups-failed", "err" => _0))]
64-
SetGroupsFailed(Error),
63+
SetGroupsFailed(std::io::Error),
6564

6665
/// The call to `setuid()` failed.
6766
#[error("{}", translate!("chroot-error-set-user-failed", "user" => _0.maybe_quote(), "err" => _1))]
68-
SetUserFailed(String, #[source] Error),
67+
SetUserFailed(String, #[source] std::io::Error),
6968
}
7069

7170
impl UError for ChrootError {

src/uu/env/src/env.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use uucore::signals::{signal_by_name_or_value, signal_name_by_value, signal_numb
4747
use uucore::translate;
4848
use uucore::{format_usage, show_warning};
4949

50-
5150
#[derive(Debug, PartialEq, thiserror::Error)]
5251
pub enum EnvError {
5352
#[error("{}", translate!("env-error-missing-closing-quote", "position" => .0, "quote" => .1))]

src/uu/kill/src/kill.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use clap::{Arg, ArgAction, Command};
99
use nix::sys::signal::{self, Signal};
1010
use nix::unistd::Pid;
11-
use std::io::Error;
1211
use uucore::display::Quotable;
1312
use uucore::error::{FromIo, UResult, USimpleError};
1413
use uucore::translate;
@@ -76,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
7675
} else {
7776
let sig = (sig as i32)
7877
.try_into()
79-
.map_err(|e| Error::from_raw_os_error(e as i32))?;
78+
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
8079
Some(sig)
8180
};
8281

@@ -254,7 +253,7 @@ fn kill(sig: Option<Signal>, pids: &[i32]) {
254253
for &pid in pids {
255254
if let Err(e) = signal::kill(Pid::from_raw(pid), sig) {
256255
show!(
257-
Error::from_raw_os_error(e as i32)
256+
std::io::Error::from_raw_os_error(e as i32)
258257
.map_err_context(|| { translate!("kill-error-sending-signal", "pid" => pid) })
259258
);
260259
}

src/uu/nohup/src/nohup.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use clap::{Arg, ArgAction, Command};
1111
use libc::{SIG_IGN, SIGHUP, dup2, signal};
1212
use std::env;
1313
use std::fs::{File, OpenOptions};
14-
use std::io::{Error, ErrorKind, IsTerminal};
14+
use std::io::{ErrorKind, IsTerminal};
1515
use std::os::unix::prelude::*;
1616
use std::os::unix::process::CommandExt;
1717
use std::path::{Path, PathBuf};
@@ -39,13 +39,13 @@ enum NohupError {
3939
CannotDetach,
4040

4141
#[error("{}", translate!("nohup-error-cannot-replace", "name" => (*_0), "err" => _1))]
42-
CannotReplace(&'static str, #[source] Error),
42+
CannotReplace(&'static str, #[source] std::io::Error),
4343

4444
#[error("{}", translate!("nohup-error-open-failed", "path" => NOHUP_OUT.quote(), "err" => _1))]
45-
OpenFailed(i32, #[source] Error),
45+
OpenFailed(i32, #[source] std::io::Error),
4646

4747
#[error("{}", translate!("nohup-error-open-failed-both", "first_path" => NOHUP_OUT.quote(), "first_err" => _1, "second_path" => _2.quote(), "second_err" => _3))]
48-
OpenFailed2(i32, #[source] Error, String, Error),
48+
OpenFailed2(i32, #[source] std::io::Error, String, std::io::Error),
4949
}
5050

5151
impl UError for NohupError {
@@ -118,7 +118,7 @@ fn replace_fds() -> UResult<()> {
118118
let new_stdin = File::open(Path::new("/dev/null"))
119119
.map_err(|e| NohupError::CannotReplace("STDIN", e))?;
120120
if unsafe { dup2(new_stdin.as_raw_fd(), 0) } != 0 {
121-
return Err(NohupError::CannotReplace("STDIN", Error::last_os_error()).into());
121+
return Err(NohupError::CannotReplace("STDIN", std::io::Error::last_os_error()).into());
122122
}
123123
}
124124

@@ -127,12 +127,14 @@ fn replace_fds() -> UResult<()> {
127127
let fd = new_stdout.as_raw_fd();
128128

129129
if unsafe { dup2(fd, 1) } != 1 {
130-
return Err(NohupError::CannotReplace("STDOUT", Error::last_os_error()).into());
130+
return Err(
131+
NohupError::CannotReplace("STDOUT", std::io::Error::last_os_error()).into(),
132+
);
131133
}
132134
}
133135

134136
if std::io::stderr().is_terminal() && unsafe { dup2(1, 2) } != 2 {
135-
return Err(NohupError::CannotReplace("STDERR", Error::last_os_error()).into());
137+
return Err(NohupError::CannotReplace("STDERR", std::io::Error::last_os_error()).into());
136138
}
137139
Ok(())
138140
}

src/uu/numfmt/src/numfmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,12 @@ mod tests {
575575
FormatOptions, InvalidModes, NumfmtOptions, Range, RoundMethod, TransformOptions, Unit,
576576
handle_args, handle_buffer, parse_unit_size, parse_unit_size_suffix,
577577
};
578-
use std::io::{BufReader, Error, ErrorKind, Read};
578+
use std::io::{BufReader, ErrorKind, Read};
579579
struct MockBuffer {}
580580

581581
impl Read for MockBuffer {
582-
fn read(&mut self, _: &mut [u8]) -> Result<usize, Error> {
583-
Err(Error::new(ErrorKind::BrokenPipe, "broken pipe"))
582+
fn read(&mut self, _: &mut [u8]) -> Result<usize, std::io::Error> {
583+
Err(std::io::Error::new(ErrorKind::BrokenPipe, "broken pipe"))
584584
}
585585
}
586586

src/uu/od/src/mockstream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
// https://github.com/lazy-bitfield/rust-mockstream/pull/2
66

7-
use std::io::{Cursor, Error, ErrorKind, Read, Result};
7+
use std::io::{Cursor, ErrorKind, Read, Result};
88

99
/// `FailingMockStream` mocks a stream which will fail upon read or write
1010
///
@@ -73,7 +73,7 @@ impl FailingMockStream {
7373
if self.repeat_count > 0 {
7474
self.repeat_count -= 1;
7575
}
76-
Err(Error::new(self.kind, self.message))
76+
Err(std::io::Error::new(self.kind, self.message))
7777
}
7878
}
7979
}

src/uu/split/src/platform/unix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
use std::env;
66
use std::ffi::{OsStr, OsString};
7-
use std::io::{BufWriter, Error, Result};
7+
use std::io::{BufWriter, Result};
88
use std::io::{ErrorKind, Write};
99
use std::path::Path;
1010
use std::process::{Child, Command, Stdio};
@@ -141,10 +141,10 @@ pub fn instantiate_current_writer(
141141
.truncate(true)
142142
.open(Path::new(filename))
143143
.map_err(|e| match e.kind() {
144-
ErrorKind::IsADirectory => Error::other(
144+
ErrorKind::IsADirectory => std::io::Error::other(
145145
translate!("split-error-is-a-directory", "dir" => filename.quote()),
146146
),
147-
_ => Error::other(
147+
_ => std::io::Error::other(
148148
translate!("split-error-unable-to-open-file", "file" => filename.quote()),
149149
),
150150
})?
@@ -154,7 +154,7 @@ pub fn instantiate_current_writer(
154154
.append(true)
155155
.open(Path::new(filename))
156156
.map_err(|_| {
157-
Error::other(translate!(
157+
std::io::Error::other(translate!(
158158
"split-error-unable-to-reopen-file",
159159
"file" => filename.quote()
160160
))

src/uu/split/src/platform/windows.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
use std::ffi::OsStr;
6-
use std::io::{BufWriter, Error, Result};
6+
use std::io::{BufWriter, Result};
77
use std::io::{ErrorKind, Write};
88
use std::path::Path;
99
use uucore::display::Quotable;
@@ -27,10 +27,10 @@ pub fn instantiate_current_writer(
2727
.truncate(true)
2828
.open(Path::new(filename))
2929
.map_err(|e| match e.kind() {
30-
ErrorKind::IsADirectory => Error::other(
30+
ErrorKind::IsADirectory => std::io::Error::other(
3131
translate!("split-error-is-a-directory", "dir" => filename.quote()),
3232
),
33-
_ => Error::other(
33+
_ => std::io::Error::other(
3434
translate!("split-error-unable-to-open-file", "file" => filename.quote()),
3535
),
3636
})?
@@ -40,7 +40,7 @@ pub fn instantiate_current_writer(
4040
.append(true)
4141
.open(Path::new(filename))
4242
.map_err(|_| {
43-
Error::other(
43+
std::io::Error::other(
4444
translate!("split-error-unable-to-reopen-file", "file" => filename.quote()),
4545
)
4646
})?

src/uu/tee/src/tee.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use std::ffi::OsString;
99
use std::fs::OpenOptions;
10-
use std::io::{Error, ErrorKind, Read, Result, Write, stderr, stdin, stdout};
10+
use std::io::{ErrorKind, Read, Result, Write, stderr, stdin, stdout};
1111
use std::path::PathBuf;
1212
use uucore::display::Quotable;
1313
use uucore::error::{UResult, strip_errno};
@@ -63,10 +63,10 @@ fn tee(options: &Options) -> Result<()> {
6363
// This is therefore just a clever way to stop all writers
6464

6565
if options.ignore_interrupts {
66-
ignore_interrupts().map_err(|_| Error::from(ErrorKind::Other))?;
66+
ignore_interrupts().map_err(|_| std::io::Error::from(ErrorKind::Other))?;
6767
}
6868
if options.output_error.is_some() {
69-
disable_pipe_errors().map_err(|_| Error::from(ErrorKind::Other))?;
69+
disable_pipe_errors().map_err(|_| std::io::Error::from(ErrorKind::Other))?;
7070
}
7171
}
7272
let mut writers: Vec<NamedWriter> = options
@@ -104,7 +104,7 @@ fn tee(options: &Options) -> Result<()> {
104104
};
105105

106106
if had_open_errors || res.is_err() || output.error_occurred() {
107-
Err(Error::from(ErrorKind::Other))
107+
Err(std::io::Error::from(ErrorKind::Other))
108108
} else {
109109
Ok(())
110110
}
@@ -217,7 +217,7 @@ impl MultiWriter {
217217
// This error kind will never be raised by the standard
218218
// library, so we can use it for early termination of
219219
// `copy`
220-
Err(Error::from(ErrorKind::Other))
220+
Err(std::io::Error::from(ErrorKind::Other))
221221
} else {
222222
Ok(())
223223
},
@@ -228,7 +228,7 @@ impl MultiWriter {
228228

229229
fn process_error(
230230
mode: Option<OutputErrorMode>,
231-
e: Error,
231+
e: std::io::Error,
232232
writer: &NamedWriter,
233233
ignored_errors: &mut usize,
234234
) -> Result<()> {

0 commit comments

Comments
 (0)