Skip to content

Commit 7fbedf5

Browse files
author
bors-servo
authored
Auto merge of #1092 - seemyvest:fix-1029, r=fitzgen
Issue #1029: Print error messages if header is a folder or unreadable r? @fitzgen
2 parents 36aa5f4 + 33a0764 commit 7fbedf5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,27 @@ impl Bindings {
15421542
}
15431543
}
15441544

1545+
#[cfg(unix)]
1546+
fn can_read(perms: &std::fs::Permissions) -> bool {
1547+
use std::os::unix::fs::PermissionsExt;
1548+
perms.mode() & 0o444 > 0
1549+
}
1550+
1551+
#[cfg(not(unix))]
1552+
fn can_read(_: &std::fs::Permissions) -> bool {
1553+
true
1554+
}
1555+
15451556
if let Some(h) = options.input_header.as_ref() {
1557+
let md = std::fs::metadata(h).ok().unwrap();
1558+
if !md.is_file() {
1559+
eprintln!("error: '{}' is a folder", h);
1560+
return Err(());
1561+
}
1562+
if !can_read(&md.permissions()) {
1563+
eprintln!("error: insufficient permissions to read '{}'", h);
1564+
return Err(());
1565+
}
15461566
options.clang_args.push(h.clone())
15471567
}
15481568

0 commit comments

Comments
 (0)