diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-10-24 02:54:07 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 02:54:07 -0500 |
commit | 7fbedf5c27116a25072527ee1b5446ea21843bc8 (patch) | |
tree | c4b78e07f7bbdd37424b9dfe9835bbd580a9207c | |
parent | 36aa5f4eca7400035a64b81fabaa399055b875a5 (diff) | |
parent | 33a0764f89f70840149a7d3ec771b5bb9990d235 (diff) |
Auto merge of #1092 - seemyvest:fix-1029, r=fitzgen
Issue #1029: Print error messages if header is a folder or unreadable
r? @fitzgen
-rw-r--r-- | src/lib.rs | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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()) } |