Skip to content

Commit dbec25b

Browse files
committed
refactor: avoid std::io::Error imports
1 parent aeade93 commit dbec25b

18 files changed

Lines changed: 63 additions & 63 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 rustix::stdio::{dup2_stderr, dup2_stdin, dup2_stdout, stdout};
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::fs::OpenOptionsExt;
1616
use std::os::unix::process::CommandExt;
1717
use std::path::{Path, PathBuf};
@@ -40,13 +40,13 @@ enum NohupError {
4040
CannotDetach,
4141

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

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

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

5252
impl UError for NohupError {
@@ -120,18 +120,20 @@ fn replace_fds() -> UResult<()> {
120120
if std::io::stdin().is_terminal() {
121121
let new_stdin = File::open(Path::new("/dev/null"))
122122
.map_err(|e| NohupError::CannotReplace("STDIN", e))?;
123-
dup2_stdin(&new_stdin).map_err(|e| NohupError::CannotReplace("STDIN", Error::from(e)))?;
123+
dup2_stdin(&new_stdin)
124+
.map_err(|e| NohupError::CannotReplace("STDIN", std::io::Error::from(e)))?;
124125
}
125126

126127
if std::io::stdout().is_terminal() {
127128
let new_stdout = find_stdout()?;
128129

129130
dup2_stdout(&new_stdout)
130-
.map_err(|e| NohupError::CannotReplace("STDOUT", Error::from(e)))?;
131+
.map_err(|e| NohupError::CannotReplace("STDOUT", std::io::Error::from(e)))?;
131132
}
132133

133134
if std::io::stderr().is_terminal() {
134-
dup2_stderr(stdout()).map_err(|e| NohupError::CannotReplace("STDERR", Error::from(e)))?;
135+
dup2_stderr(stdout())
136+
.map_err(|e| NohupError::CannotReplace("STDERR", std::io::Error::from(e)))?;
135137
}
136138
Ok(())
137139
}

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: 7 additions & 7 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};
10+
use std::io::{ErrorKind, Read, Result, Write, stderr, stdin};
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
@@ -107,7 +107,7 @@ fn tee(options: &Options) -> Result<()> {
107107
};
108108

109109
if had_open_errors || res.is_err() || output.error_occurred() {
110-
Err(Error::from(ErrorKind::Other))
110+
Err(std::io::Error::from(ErrorKind::Other))
111111
} else {
112112
Ok(())
113113
}
@@ -147,7 +147,7 @@ struct MultiWriter {
147147
writers: Vec<NamedWriter>,
148148
output_error_mode: Option<OutputErrorMode>,
149149
ignored_errors: usize,
150-
aborted: Option<Error>,
150+
aborted: Option<std::io::Error>,
151151
}
152152

153153
impl MultiWriter {
@@ -215,7 +215,7 @@ impl MultiWriter {
215215
// This error kind will never be raised by the standard
216216
// library, so we can use it for early termination of
217217
// `copy`
218-
Err(Error::from(ErrorKind::Other))
218+
Err(std::io::Error::from(ErrorKind::Other))
219219
} else {
220220
Ok(())
221221
},
@@ -226,7 +226,7 @@ impl MultiWriter {
226226

227227
fn process_error(
228228
mode: Option<OutputErrorMode>,
229-
e: Error,
229+
e: std::io::Error,
230230
writer: &NamedWriter,
231231
ignored_errors: &mut usize,
232232
) -> Result<()> {

0 commit comments

Comments
 (0)