Skip to content

Commit

Permalink
Auto merge of #1092 - seemyvest:fix-1029, r=fitzgen
Browse files Browse the repository at this point in the history
Issue #1029: Print error messages if header is a folder or unreadable

r? @fitzgen
  • Loading branch information
bors-servo authored Oct 24, 2017
2 parents 36aa5f4 + 33a0764 commit 7fbedf5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,27 @@ impl Bindings {
}
}

#[cfg(unix)]
fn can_read(perms: &std::fs::Permissions) -> bool {
use std::os::unix::fs::PermissionsExt;
perms.mode() & 0o444 > 0
}

#[cfg(not(unix))]
fn can_read(_: &std::fs::Permissions) -> bool {
true
}

if let Some(h) = options.input_header.as_ref() {
let md = std::fs::metadata(h).ok().unwrap();
if !md.is_file() {
eprintln!("error: '{}' is a folder", h);
return Err(());
}
if !can_read(&md.permissions()) {
eprintln!("error: insufficient permissions to read '{}'", h);
return Err(());
}
options.clang_args.push(h.clone())
}

Expand Down

0 comments on commit 7fbedf5

Please sign in to comment.