summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-10-24 02:54:07 -0500
committerGitHub <noreply@github.com>2017-10-24 02:54:07 -0500
commit7fbedf5c27116a25072527ee1b5446ea21843bc8 (patch)
treec4b78e07f7bbdd37424b9dfe9835bbd580a9207c
parent36aa5f4eca7400035a64b81fabaa399055b875a5 (diff)
parent33a0764f89f70840149a7d3ec771b5bb9990d235 (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.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6e4ba7aa..7e2db0d5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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())
}