shadow-core: use uucore::error::strip_errno instead of hand-rolling

Replace the local " (os error N)" suffix stripping with uucore's existing
strip_errno helper, per review on #171. Adds uucore (already in the
dependency tree via the tool crates) to shadow-core.
This commit is contained in:
Pierre Warnier
2026-06-10 13:34:04 +02:00
parent 15f8ecc505
commit dbfec6e5b7
3 changed files with 6 additions and 9 deletions
Generated
+1
View File
@@ -662,6 +662,7 @@ dependencies = [
"subtle",
"tempfile",
"thiserror",
"uucore",
"zeroize",
]
+1
View File
@@ -18,6 +18,7 @@ path = "src/lib.rs"
libc = { workspace = true }
rustix = { workspace = true }
thiserror = { workspace = true }
uucore = { workspace = true }
zeroize = { workspace = true }
subtle = { workspace = true }
landlock = { workspace = true, optional = true }
+4 -9
View File
@@ -19,15 +19,10 @@
#[must_use]
pub fn strerror(errno: i32) -> String {
// `io::Error::from_raw_os_error` carries libc's `strerror` text, but its
// `Display` appends Rust's own " (os error N)" suffix. Strip that so the
// result is the bare OS message (matching GNU/coreutils output). The
// suffix is emitted verbatim in English regardless of locale, so a
// localized message cannot contain it earlier in the string.
let rendered = std::io::Error::from_raw_os_error(errno).to_string();
match rendered.rfind(" (os error ") {
Some(cut) => rendered[..cut].to_string(),
None => rendered,
}
// `Display` appends Rust's own " (os error N)" suffix. `strip_errno` (the
// same helper uucore uses for its own I/O errors) removes it, leaving the
// bare OS message — matching GNU/coreutils output.
uucore::error::strip_errno(&std::io::Error::from_raw_os_error(errno))
}
/// The OS message for `EACCES` ("Permission denied"), sourced from libc.