Skip to content

Commit d44ca03

Browse files
committed
---
yaml --- r: 161757 b: refs/heads/master c: 3980cde h: refs/heads/master i: 161755: 8548bad v: v3
1 parent adca5d0 commit d44ca03

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 805a06ca6a4f0999e13508e6271e3589f2c4c1b2
2+
refs/heads/master: 3980cdecd073789fb5ff7256e2ca40685a289b01
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cafe2966770ff377aad6dd9fd808e68055587c58
55
refs/heads/try: 0f0d21c1eb5c7be04d323e0b06faf252ad790af6

trunk/src/libstd/io/fs.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
use clone::Clone;
5454
use io::standard_error;
5555
use io::{FilePermission, Write, Open, FileAccess, FileMode, FileType};
56-
use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader};
56+
use io::{IoResult, IoError, InvalidInput};
57+
use io::{FileStat, SeekStyle, Seek, Writer, Reader};
5758
use io::{Read, Truncate, ReadWrite, Append};
5859
use io::UpdateIoError;
5960
use io;
@@ -134,13 +135,26 @@ impl File {
134135
pub fn open_mode(path: &Path,
135136
mode: FileMode,
136137
access: FileAccess) -> IoResult<File> {
137-
fs_imp::open(path, mode, access).map(|fd| {
138-
File {
139-
path: path.clone(),
140-
fd: fd,
141-
last_nread: -1
138+
fs_imp::open(path, mode, access).and_then(|fd| {
139+
// On *BSD systems, we can open a directory as a file and read from it:
140+
// fd=open("/tmp", O_RDONLY); read(fd, buf, N);
141+
// due to an old tradition before the introduction of opendir(3).
142+
// We explicitly reject it because there are few use cases.
143+
if cfg!(not(any(windows, target_os = "linux", target_os = "android"))) &&
144+
try!(fd.fstat()).kind == FileType::Directory {
145+
Err(IoError {
146+
kind: InvalidInput,
147+
desc: "is a directory",
148+
detail: None
149+
})
150+
} else {
151+
Ok(File {
152+
path: path.clone(),
153+
fd: fd,
154+
last_nread: -1
155+
})
142156
}
143-
}).update_err("couldn't open file", |e| {
157+
}).update_err("couldn't open path as file", |e| {
144158
format!("{}; path={}; mode={}; access={}", e, path.display(),
145159
mode_string(mode), access_string(access))
146160
})
@@ -886,7 +900,7 @@ mod test {
886900
let filename = &tmpdir.join("file_that_does_not_exist.txt");
887901
let result = File::open_mode(filename, Open, Read);
888902

889-
error!(result, "couldn't open file");
903+
error!(result, "couldn't open path as file");
890904
if cfg!(unix) {
891905
error!(result, "no such file or directory");
892906
}

trunk/src/test/compile-fail/issue-5806.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
// option. This file may not be copied, modified, or distributed
1919
// except according to those terms.
2020

21-
// ignore-freebsd FIXME #12460
22-
2321
#[path = "../compile-fail"]
24-
mod foo; //~ ERROR: illegal operation on a directory
22+
mod foo; //~ ERROR: a directory
2523

2624
fn main() {}

0 commit comments

Comments
 (0)