Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gix-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bstr = "1.12.0"
gix-path = { version = "^0.11.2", path = "../gix-path" }
gix-features = { version = "^0.46.2", path = "../gix-features", features = ["fs-read-dir"] }
gix-utils = { version = "^0.3.1", path = "../gix-utils" }
thiserror = "2.0.18"
gix-error = { version = "0.1.0", path = "../gix-error" }
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"] }

# For `Capabilities` to assure parallel operation works.
Expand Down
27 changes: 11 additions & 16 deletions gix-fs/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ use std::{

use bstr::{BStr, BString, ByteSlice};

use gix_error::{message, ErrorExt, ResultExt};

use crate::Stack;

///
pub mod to_normal_path_components {
use std::path::PathBuf;

/// The error used in [`ToNormalPathComponents::to_normal_path_components()`](super::ToNormalPathComponents::to_normal_path_components()).
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Input path \"{path}\" contains relative or absolute components", path = .0.display())]
NotANormalComponent(PathBuf),
#[error("Could not convert to UTF8 or from UTF8 due to ill-formed input")]
IllegalUtf8,
}
pub type Error = gix_error::Exn<gix_error::Message>;
}

/// Obtain an iterator over `OsStr`-components which are normal, none-relative and not absolute.
Expand All @@ -46,9 +39,11 @@ fn component_to_os_str<'a>(
) -> Result<&'a OsStr, to_normal_path_components::Error> {
match component {
Component::Normal(os_str) => Ok(os_str),
_ => Err(to_normal_path_components::Error::NotANormalComponent(
path_with_component.to_owned(),
)),
_ => Err(message!(
"Input path \"{}\" contains relative or absolute components",
path_with_component.display()
)
.raise()),
}
}

Expand Down Expand Up @@ -81,7 +76,7 @@ fn bytes_component_to_os_str<'a>(
return None;
}
let component = match gix_path::try_from_byte_slice(component.as_bstr())
.map_err(|_| to_normal_path_components::Error::IllegalUtf8)
.or_raise(|| message("Could not convert to UTF8 or from UTF8 due to ill-formed input"))
{
Ok(c) => c,
Err(err) => return Some(Err(err)),
Expand Down Expand Up @@ -178,7 +173,7 @@ impl Stack {
break;
}
}
Err(err) => return Err(std::io::Error::other(format!("{err}"))),
Err(err) => return Err(std::io::Error::other(err.to_string())),
}
}

Expand All @@ -197,7 +192,7 @@ impl Stack {
}

while let Some(comp) = components.next() {
let comp = comp.map_err(std::io::Error::other)?;
let comp = comp.map_err(|e| std::io::Error::other(e.into_error()))?;
let is_last_component = components.peek().is_none();
self.current_is_directory = !is_last_component;
self.current.push(comp);
Expand Down
Loading