diff options
author | seemyvest <32128784+seemyvest@users.noreply.github.com> | 2017-10-23 12:03:36 +1100 |
---|---|---|
committer | seemyvest <32128784+seemyvest@users.noreply.github.com> | 2017-10-24 08:28:58 +1100 |
commit | 33a0764f89f70840149a7d3ec771b5bb9990d235 (patch) | |
tree | 7dc349756b15a549e2a824bbedca0e5e6884df6e | |
parent | 8582a90ee76384df63876c879646da0c1555166b (diff) |
Issue #1029: Print error messages if header is a folder or unreadable
-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()) } |