Skip to content

Commit

Permalink
Change into PathBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuroXina authored and emilio committed Dec 29, 2021
1 parent 0d95ea1 commit e24afad
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,24 +2151,26 @@ fn ensure_libclang_is_loaded() {}
#[non_exhaustive]
pub enum BindgenError {
/// The header was a folder.
FolderAsHeader(String),
FolderAsHeader(PathBuf),
/// Permissions to read the header is insufficient.
InsufficientPermissions(String),
InsufficientPermissions(PathBuf),
/// The header does not exist.
NotExist(String),
NotExist(PathBuf),
/// Clang diagnosed an error.
ClangDiagnostic(String),
}

impl std::fmt::Display for BindgenError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BindgenError::FolderAsHeader(h) => write!(f, "'{}' is a folder", h),
BindgenError::FolderAsHeader(h) => {
write!(f, "'{}' is a folder", h.display())
}
BindgenError::InsufficientPermissions(h) => {
write!(f, "insufficient permissions to read '{}'", h)
write!(f, "insufficient permissions to read '{}'", h.display())
}
BindgenError::NotExist(h) => {
write!(f, "header '{}' does not exist.", h)
write!(f, "header '{}' does not exist.", h.display())
}
BindgenError::ClangDiagnostic(message) => {
write!(f, "clang diagnosed error: {}", message)
Expand Down Expand Up @@ -2353,18 +2355,19 @@ impl Bindings {
}

if let Some(h) = options.input_header.as_ref() {
if let Ok(md) = std::fs::metadata(h) {
let path = Path::new(h);
if let Ok(md) = std::fs::metadata(path) {
if md.is_dir() {
return Err(BindgenError::FolderAsHeader(h.into()));
return Err(BindgenError::FolderAsHeader(path.into()));
}
if !can_read(&md.permissions()) {
return Err(BindgenError::InsufficientPermissions(
h.into(),
path.into(),
));
}
options.clang_args.push(h.clone())
} else {
return Err(BindgenError::NotExist(h.into()));
return Err(BindgenError::NotExist(path.into()));
}
}

Expand Down

0 comments on commit e24afad

Please sign in to comment.