Skip to content

Commit c1e0d9e

Browse files
committed
refactor: error handling in buf_copy
1 parent 6b8a5a1 commit c1e0d9e

3 files changed

Lines changed: 8 additions & 21 deletions

File tree

src/uucore/src/lib/features/buf_copy.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//! used by utilities to work around the limitations of Rust's `fs::copy` which
1010
//! does not handle copying special files (e.g pipes, character/block devices).
1111
12-
pub mod common;
13-
1412
#[cfg(any(target_os = "linux", target_os = "android"))]
1513
pub mod linux;
1614
#[cfg(any(target_os = "linux", target_os = "android"))]

src/uucore/src/lib/features/buf_copy/common.rs renamed to src/uucore/src/lib/features/buf_copy/error.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ use crate::error::UError;
99
#[derive(Debug)]
1010
pub enum Error {
1111
Io(std::io::Error),
12-
WriteError(String),
12+
}
13+
14+
impl From<rustix::io::Errno> for Error {
15+
fn from(value: rustix::io::Errno) -> Self {
16+
Self::Io(value.into())
17+
}
1318
}
1419

1520
impl std::fmt::Display for Error {
1621
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1722
match self {
18-
Self::WriteError(msg) => write!(f, "splice() write error: {msg}"),
1923
Self::Io(err) => write!(f, "I/O error: {err}"),
2024
}
2125
}
2226
}
2327

2428
impl std::error::Error for Error {}
2529

26-
impl UError for Error {
27-
fn code(&self) -> i32 {
28-
1
29-
}
30-
31-
fn usage(&self) -> bool {
32-
false
33-
}
34-
}
30+
impl UError for Error {}

src/uucore/src/lib/features/buf_copy/linux.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
os::fd::{AsFd, AsRawFd},
1414
};
1515

16-
use super::common::Error;
16+
use super::error::Error;
1717

1818
/// A readable file descriptor.
1919
pub trait FdReadable: Read + AsRawFd + AsFd {}
@@ -25,13 +25,6 @@ pub trait FdWritable: Write + AsFd + AsRawFd {}
2525

2626
impl<T> FdWritable for T where T: Write + AsFd + AsRawFd {}
2727

28-
/// Conversion from a `rustix::io::Errno` into our `Error` which implements `UError`.
29-
impl From<rustix::io::Errno> for Error {
30-
fn from(error: rustix::io::Errno) -> Self {
31-
Self::Io(std::io::Error::from(error))
32-
}
33-
}
34-
3528
/// Copy data from `Read` implementor `source` into a `Write` implementor
3629
/// `dest`. This works by reading a chunk of data from `source` and writing the
3730
/// data to `dest` in a loop.

0 commit comments

Comments
 (0)