mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
touch: move to thiserror
This commit is contained in:
parent
70f3429102
commit
9de6393e2c
3 changed files with 14 additions and 31 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -3123,6 +3123,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"thiserror 2.0.11",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3172,6 +3173,7 @@ dependencies = [
|
||||||
"rayon",
|
"rayon",
|
||||||
"self_cell",
|
"self_cell",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"thiserror 2.0.11",
|
||||||
"unicode-width 0.2.0",
|
"unicode-width 0.2.0",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
@ -3304,6 +3306,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"filetime",
|
"filetime",
|
||||||
"parse_datetime",
|
"parse_datetime",
|
||||||
|
"thiserror 2.0.11",
|
||||||
"uucore",
|
"uucore",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
|
@ -22,6 +22,7 @@ filetime = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
parse_datetime = { workspace = true }
|
parse_datetime = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["libc"] }
|
uucore = { workspace = true, features = ["libc"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
|
|
|
@ -4,29 +4,31 @@
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore (misc) uioerror
|
// spell-checker:ignore (misc) uioerror
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
use std::fmt::{Display, Formatter, Result};
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use filetime::FileTime;
|
use filetime::FileTime;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use thiserror::Error;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{UError, UIoError};
|
use uucore::error::{UError, UIoError};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub enum TouchError {
|
pub enum TouchError {
|
||||||
|
#[error("Unable to parse date: {0}")]
|
||||||
InvalidDateFormat(String),
|
InvalidDateFormat(String),
|
||||||
|
|
||||||
/// The source time couldn't be converted to a [chrono::DateTime]
|
/// The source time couldn't be converted to a [chrono::DateTime]
|
||||||
|
#[error("Source has invalid access or modification time: {0}")]
|
||||||
InvalidFiletime(FileTime),
|
InvalidFiletime(FileTime),
|
||||||
|
|
||||||
/// The reference file's attributes could not be found or read
|
/// The reference file's attributes could not be found or read
|
||||||
|
#[error("failed to get attributes of {}: {}", .0.quote(), to_uioerror(.1))]
|
||||||
ReferenceFileInaccessible(PathBuf, std::io::Error),
|
ReferenceFileInaccessible(PathBuf, std::io::Error),
|
||||||
|
|
||||||
/// An error getting a path to stdout on Windows
|
/// An error getting a path to stdout on Windows
|
||||||
|
#[error("GetFinalPathNameByHandleW failed with code {0}")]
|
||||||
WindowsStdoutPathError(String),
|
WindowsStdoutPathError(String),
|
||||||
|
|
||||||
/// An error encountered on a specific file
|
/// An error encountered on a specific file
|
||||||
|
#[error("{error}")]
|
||||||
TouchFileError {
|
TouchFileError {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
index: usize,
|
index: usize,
|
||||||
|
@ -34,31 +36,6 @@ pub enum TouchError {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for TouchError {}
|
|
||||||
impl UError for TouchError {}
|
|
||||||
impl Display for TouchError {
|
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
|
||||||
match self {
|
|
||||||
Self::InvalidDateFormat(s) => write!(f, "Unable to parse date: {s}"),
|
|
||||||
Self::InvalidFiletime(time) => {
|
|
||||||
write!(f, "Source has invalid access or modification time: {time}",)
|
|
||||||
}
|
|
||||||
Self::ReferenceFileInaccessible(path, err) => {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"failed to get attributes of {}: {}",
|
|
||||||
path.quote(),
|
|
||||||
to_uioerror(err)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::WindowsStdoutPathError(code) => {
|
|
||||||
write!(f, "GetFinalPathNameByHandleW failed with code {code}")
|
|
||||||
}
|
|
||||||
Self::TouchFileError { error, .. } => write!(f, "{error}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_uioerror(err: &std::io::Error) -> UIoError {
|
fn to_uioerror(err: &std::io::Error) -> UIoError {
|
||||||
let copy = if let Some(code) = err.raw_os_error() {
|
let copy = if let Some(code) = err.raw_os_error() {
|
||||||
std::io::Error::from_raw_os_error(code)
|
std::io::Error::from_raw_os_error(code)
|
||||||
|
@ -67,3 +44,5 @@ fn to_uioerror(err: &std::io::Error) -> UIoError {
|
||||||
};
|
};
|
||||||
UIoError::from(copy)
|
UIoError::from(copy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UError for TouchError {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue