From 4603d44926818288c1761170c7960874189c7ade Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Sun, 27 Oct 2024 02:20:47 +0200 Subject: [PATCH] make unix build Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com> --- crates/core/src/backend/ignore.rs | 12 ++++++----- crates/core/src/backend/node.rs | 36 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/core/src/backend/ignore.rs b/crates/core/src/backend/ignore.rs index 87e3415a..1c0431e4 100644 --- a/crates/core/src/backend/ignore.rs +++ b/crates/core/src/backend/ignore.rs @@ -1,4 +1,6 @@ #[cfg(not(windows))] +use std::num::TryFromIntError; +#[cfg(not(windows))] use std::os::unix::fs::{FileTypeExt, MetadataExt}; use std::{ @@ -60,7 +62,7 @@ pub enum IgnoreErrorKind { CtimeConversionToTimestampFailed { ctime: i64, ctime_nsec: i64, - source: ignore::Error, + source: TryFromIntError, }, /// Error acquiring metadata for `{name}`: `{source:?}` AcquiringMetadataFailed { name: String, source: ignore::Error }, @@ -649,13 +651,13 @@ fn map_entry( let ctime = Utc .timestamp_opt( m.ctime(), - m.ctime_nsec() - .try_into() - .map_err(|err| IgnoreErrorKind::CtimeConversionFailed { + m.ctime_nsec().try_into().map_err(|err| { + IgnoreErrorKind::CtimeConversionToTimestampFailed { ctime: m.ctime(), ctime_nsec: m.ctime_nsec(), source: err, - })?, + } + })?, ) .single() .map(|dt| dt.with_timezone(&Local)); diff --git a/crates/core/src/backend/node.rs b/crates/core/src/backend/node.rs index 5127319b..55695a0e 100644 --- a/crates/core/src/backend/node.rs +++ b/crates/core/src/backend/node.rs @@ -9,12 +9,12 @@ use std::{ #[cfg(not(windows))] use std::fmt::Write; #[cfg(not(windows))] +use std::num::ParseIntError; +#[cfg(not(windows))] use std::os::unix::ffi::OsStrExt; use chrono::{DateTime, Local}; use derive_more::Constructor; -#[cfg(not(windows))] -use displaydoc::Display; use serde_aux::prelude::*; use serde_derive::{Deserialize, Serialize}; use serde_with::{ @@ -22,23 +22,21 @@ use serde_with::{ formats::Padded, serde_as, skip_serializing_none, DefaultOnNull, }; -#[cfg(not(windows))] -use thiserror::Error; use crate::blob::{tree::TreeId, DataId}; #[cfg(not(windows))] /// [`NodeErrorKind`] describes the errors that can be returned by an action utilizing a node in Backends -#[derive(thiserror::Error, Debug, Display)] +#[derive(thiserror::Error, Debug, displaydoc::Display)] #[non_exhaustive] -pub enum NodeErrorKind { +pub enum NodeErrorKind<'a> { /// Unexpected EOF while parsing filename: `{file_name}` #[cfg(not(windows))] UnexpectedEOF { /// The filename file_name: String, /// The remaining chars - chars: std::str::Chars, + chars: std::str::Chars<'a>, }, /// Invalid unicode #[cfg(not(windows))] @@ -48,7 +46,7 @@ pub enum NodeErrorKind { /// The unicode codepoint unicode: u32, /// The remaining chars - chars: std::str::Chars, + chars: std::str::Chars<'a>, }, /// Unrecognized Escape while parsing filename: `{file_name}` #[cfg(not(windows))] @@ -56,7 +54,7 @@ pub enum NodeErrorKind { /// The filename file_name: String, /// The remaining chars - chars: std::str::Chars, + chars: std::str::Chars<'a>, }, /// Parsing hex chars {chars:?} failed for `{hex}` in filename: `{file_name}` : `{source}` #[cfg(not(windows))] @@ -66,7 +64,7 @@ pub enum NodeErrorKind { /// The hex string hex: String, /// The remaining chars - chars: std::str::Chars, + chars: std::str::Chars<'a>, /// The error that occurred source: ParseIntError, }, @@ -78,14 +76,14 @@ pub enum NodeErrorKind { /// The target type target: String, /// The remaining chars - chars: std::str::Chars, + chars: std::str::Chars<'a>, /// The error that occurred source: ParseIntError, }, } #[cfg(not(windows))] -pub(crate) type NodeResult = Result; +pub(crate) type NodeResult<'a, T> = Result>; #[derive( Default, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Constructor, PartialOrd, Ord, @@ -464,7 +462,7 @@ fn escape_filename(name: &OsStr) -> String { /// /// * `s` - The escaped filename // inspired by the enquote crate -fn unescape_filename(s: &str) -> NodeResult { +fn unescape_filename(s: &str) -> NodeResult<'_, OsString> { let mut chars = s.chars(); let mut u = Vec::new(); loop { @@ -498,7 +496,7 @@ fn unescape_filename(s: &str) -> NodeResult { NodeErrorKind::ParsingHexFailed { file_name: s.to_string(), hex: hex.to_string(), - chars, + chars: chars.clone(), source: err, } })?); @@ -509,7 +507,7 @@ fn unescape_filename(s: &str) -> NodeResult { |err| NodeErrorKind::ParsingUnicodeFailed { file_name: s.to_string(), target: "u32".to_string(), - chars, + chars: chars.clone(), source: err, }, )?; @@ -517,7 +515,7 @@ fn unescape_filename(s: &str) -> NodeResult { NodeErrorKind::InvalidUnicode { file_name: s.to_string(), unicode: n, - chars, + chars: chars.clone(), }, )?; let mut bytes = vec![0u8; c.len_utf8()]; @@ -529,7 +527,7 @@ fn unescape_filename(s: &str) -> NodeResult { |err| NodeErrorKind::ParsingUnicodeFailed { file_name: s.to_string(), target: "u32".to_string(), - chars, + chars: chars.clone(), source: err, }, )?; @@ -537,7 +535,7 @@ fn unescape_filename(s: &str) -> NodeResult { NodeErrorKind::InvalidUnicode { file_name: s.to_string(), unicode: n, - chars, + chars: chars.clone(), }, )?; let mut bytes = vec![0u8; c.len_utf8()]; @@ -547,7 +545,7 @@ fn unescape_filename(s: &str) -> NodeResult { _ => { return Err(NodeErrorKind::UnrecognizedEscape { file_name: s.to_string(), - chars, + chars: chars.clone(), }) } },