Make os::getcwd() return IoResult<Path>

os::getcwd() panics if the current directory is not available. According
to getcwd(3), there are three cases:

- EACCES: Permission denied.
- ENOENT: The current working directory has been removed.
- ERANGE: The buffer size is less than the actual absolute path.

This commit makes os::getcwd() return IoResult<Path>, not just Path,
preventing it from panicking.

As os::make_absolute() depends on os::getcwd(), it is also modified to
return IoResult<Path>.

Fixes #16946.

[breaking-change]
This commit is contained in:
Barosl Lee
2014-11-11 14:38:20 +09:00
parent 09e2ad13d0
commit 6f422c4c05
12 changed files with 56 additions and 43 deletions

View File

@@ -974,7 +974,7 @@ mod tests {
let prog = pwd_cmd().spawn().unwrap();
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
let parent_dir = os::getcwd();
let parent_dir = os::getcwd().unwrap();
let child_dir = Path::new(output.as_slice().trim());
let parent_stat = parent_dir.stat().unwrap();
@@ -989,7 +989,7 @@ mod tests {
use os;
// test changing to the parent of os::getcwd() because we know
// the path exists (and os::getcwd() is not expected to be root)
let parent_dir = os::getcwd().dir_path();
let parent_dir = os::getcwd().unwrap().dir_path();
let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap();
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();