diff options
| author | Barosl Lee <vcs@barosl.com> | 2014-11-11 17:13:10 +0900 |
|---|---|---|
| committer | Barosl Lee <vcs@barosl.com> | 2014-11-19 05:31:45 +0900 |
| commit | 5de56b3ca1defd9206db8364ecef5f3fd8cc5b38 (patch) | |
| tree | c43f443927adb46f158f5b1499b81ee67aac7a98 /src/libstd | |
| parent | 6f422c4c05f4d108ba6429a174aa0c2ef3b183fa (diff) | |
| download | rust-5de56b3ca1defd9206db8364ecef5f3fd8cc5b38.tar.gz rust-5de56b3ca1defd9206db8364ecef5f3fd8cc5b38.zip | |
Make os::change_dir() return IoResult<()>
os::change_dir() returns bool, without a meaningful error message. Change it to return IoResult<()> to indicate what IoError caused the failure. Fixes #16315. [breaking-change]
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/os.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 971138c06fb..cf22b8014ca 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -867,32 +867,33 @@ pub fn make_absolute(p: &Path) -> IoResult<Path> { /// use std::path::Path; /// /// let root = Path::new("/"); -/// assert!(os::change_dir(&root)); +/// assert!(os::change_dir(&root).is_ok()); /// println!("Successfully changed working directory to {}!", root.display()); /// ``` -pub fn change_dir(p: &Path) -> bool { +pub fn change_dir(p: &Path) -> IoResult<()> { return chdir(p); #[cfg(windows)] - fn chdir(p: &Path) -> bool { - let p = match p.as_str() { - Some(s) => { - let mut p = s.utf16_units().collect::<Vec<u16>>(); - p.push(0); - p - } - None => return false, - }; + fn chdir(p: &Path) -> IoResult<()> { + let mut p = p.as_str().unwrap().utf16_units().collect::<Vec<u16>>(); + p.push(0); + unsafe { - libc::SetCurrentDirectoryW(p.as_ptr()) != (0 as libc::BOOL) + match libc::SetCurrentDirectoryW(p.as_ptr()) != (0 as libc::BOOL) { + true => Ok(()), + false => Err(IoError::last_error()), + } } } #[cfg(unix)] - fn chdir(p: &Path) -> bool { + fn chdir(p: &Path) -> IoResult<()> { p.with_c_str(|buf| { unsafe { - libc::chdir(buf) == (0 as c_int) + match libc::chdir(buf) == (0 as c_int) { + true => Ok(()), + false => Err(IoError::last_error()), + } } }) } |
