Skip to content

Commit 8c157ed

Browse files
committed
native: Recognize EISDIR
This recognizes the EISDIR error code on both windows and unix platforms to provide a more descriptive error condition.
1 parent 40ab198 commit 8c157ed

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/libnative/io/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ fn translate_error(errno: i32, detail: bool) -> IoError {
105105
libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"),
106106
libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"),
107107

108+
// libuv maps this error code to EISDIR. we do too. if it is found
109+
// to be incorrect, we can add in some more machinery to only
110+
// return this message when ERROR_INVALID_FUNCTION after certain
111+
// win32 calls.
112+
libc::ERROR_INVALID_FUNCTION => (io::InvalidInput,
113+
"illegal operation on a directory"),
114+
108115
x => {
109116
debug!("ignoring {}: {}", x, os::last_os_error());
110117
(io::OtherIoError, "unknown error")
@@ -127,6 +134,7 @@ fn translate_error(errno: i32, detail: bool) -> IoError {
127134
libc::EADDRNOTAVAIL => (io::ConnectionRefused, "address not available"),
128135
libc::EADDRINUSE => (io::ConnectionRefused, "address in use"),
129136
libc::ENOENT => (io::FileNotFound, "no such file or directory"),
137+
libc::EISDIR => (io::InvalidInput, "illegal operation on a directory"),
130138

131139
// These two constants can have the same value on some systems, but
132140
// different values on others, so we can't use a match clause

src/libstd/libc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,7 @@ pub mod consts {
16231623
pub static O_NOINHERIT: c_int = 128;
16241624

16251625
pub static ERROR_SUCCESS : c_int = 0;
1626+
pub static ERROR_INVALID_FUNCTION: c_int = 1;
16261627
pub static ERROR_FILE_NOT_FOUND: c_int = 2;
16271628
pub static ERROR_ACCESS_DENIED: c_int = 5;
16281629
pub static ERROR_INVALID_HANDLE : c_int = 6;

0 commit comments

Comments
 (0)