libstd: explicitly disallow io::fs::File to open a directory.

On *BSD systems, we can open(2) a directory and directly read(2) from
it due to an old tradition.  We should avoid doing so by explicitly
calling fstat(2) to check the type of the opened file.

Opening a directory as a module file can't always be avoided.
Even when there's no "path" attribute trick involved, there can always
be a *directory* named "my_module.rs".

Fix #12460

Signed-off-by: NODA, Kai <nodakai@gmail.com>
This commit is contained in:
NODA, Kai 2014-12-03 06:06:59 +08:00
parent 805a06ca6a
commit 3980cdecd0
2 changed files with 23 additions and 11 deletions

View file

@ -18,9 +18,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-freebsd FIXME #12460
#[path = "../compile-fail"]
mod foo; //~ ERROR: illegal operation on a directory
mod foo; //~ ERROR: a directory
fn main() {}