Skip to content

Commit

Permalink
make unix build
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Oct 27, 2024
1 parent e5c9aa1 commit 4603d44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
12 changes: 7 additions & 5 deletions crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(not(windows))]
use std::num::TryFromIntError;
#[cfg(not(windows))]
use std::os::unix::fs::{FileTypeExt, MetadataExt};

use std::{
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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));
Expand Down
36 changes: 17 additions & 19 deletions crates/core/src/backend/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@ 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::{
base64::{Base64, Standard},
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))]
Expand All @@ -48,15 +46,15 @@ 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))]
UnrecognizedEscape {
/// 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))]
Expand All @@ -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,
},
Expand All @@ -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<T> = Result<T, NodeErrorKind>;
pub(crate) type NodeResult<'a, T> = Result<T, NodeErrorKind<'a>>;

#[derive(
Default, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Constructor, PartialOrd, Ord,
Expand Down Expand Up @@ -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<OsString> {
fn unescape_filename(s: &str) -> NodeResult<'_, OsString> {
let mut chars = s.chars();
let mut u = Vec::new();
loop {
Expand Down Expand Up @@ -498,7 +496,7 @@ fn unescape_filename(s: &str) -> NodeResult<OsString> {
NodeErrorKind::ParsingHexFailed {
file_name: s.to_string(),
hex: hex.to_string(),
chars,
chars: chars.clone(),
source: err,
}
})?);
Expand All @@ -509,15 +507,15 @@ fn unescape_filename(s: &str) -> NodeResult<OsString> {
|err| NodeErrorKind::ParsingUnicodeFailed {
file_name: s.to_string(),
target: "u32".to_string(),
chars,
chars: chars.clone(),
source: err,
},
)?;
let c = std::char::from_u32(n).ok_or(
NodeErrorKind::InvalidUnicode {
file_name: s.to_string(),
unicode: n,
chars,
chars: chars.clone(),
},
)?;
let mut bytes = vec![0u8; c.len_utf8()];
Expand All @@ -529,15 +527,15 @@ fn unescape_filename(s: &str) -> NodeResult<OsString> {
|err| NodeErrorKind::ParsingUnicodeFailed {
file_name: s.to_string(),
target: "u32".to_string(),
chars,
chars: chars.clone(),
source: err,
},
)?;
let c = std::char::from_u32(n).ok_or(
NodeErrorKind::InvalidUnicode {
file_name: s.to_string(),
unicode: n,
chars,
chars: chars.clone(),
},
)?;
let mut bytes = vec![0u8; c.len_utf8()];
Expand All @@ -547,7 +545,7 @@ fn unescape_filename(s: &str) -> NodeResult<OsString> {
_ => {
return Err(NodeErrorKind::UnrecognizedEscape {
file_name: s.to_string(),
chars,
chars: chars.clone(),
})
}
},
Expand Down

0 comments on commit 4603d44

Please sign in to comment.