about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorBarosl Lee <vcs@barosl.com>2014-11-11 14:38:20 +0900
committerBarosl Lee <vcs@barosl.com>2014-11-19 05:31:45 +0900
commit6f422c4c05f4d108ba6429a174aa0c2ef3b183fa (patch)
treeb393a680897f0d6a80b96f1fda5c6fcb636f8cc5 /src/libstd/io
parent09e2ad13d0aa01143bcb20dece3ff6c5a7e34ea3 (diff)
downloadrust-6f422c4c05f4d108ba6429a174aa0c2ef3b183fa.tar.gz
rust-6f422c4c05f4d108ba6429a174aa0c2ef3b183fa.zip
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]
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/process.rs4
-rw-r--r--src/libstd/io/tempfile.rs3
-rw-r--r--src/libstd/io/test.rs2
3 files changed, 5 insertions, 4 deletions
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs
index 16e568f30f2..592ec0681a9 100644
--- a/src/libstd/io/process.rs
+++ b/src/libstd/io/process.rs
@@ -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();
diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs
index e9d6ef2e341..a232231733d 100644
--- a/src/libstd/io/tempfile.rs
+++ b/src/libstd/io/tempfile.rs
@@ -35,7 +35,8 @@ impl TempDir {
     /// If no directory can be created, `Err` is returned.
     pub fn new_in(tmpdir: &Path, suffix: &str) -> IoResult<TempDir> {
         if !tmpdir.is_absolute() {
-            return TempDir::new_in(&os::make_absolute(tmpdir), suffix);
+            let abs_tmpdir = try!(os::make_absolute(tmpdir));
+            return TempDir::new_in(&abs_tmpdir, suffix);
         }
 
         static CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs
index 6571dc41585..a153ead2a38 100644
--- a/src/libstd/io/test.rs
+++ b/src/libstd/io/test.rs
@@ -75,7 +75,7 @@ fn base_port() -> u16 {
     ];
 
     // FIXME (#9639): This needs to handle non-utf8 paths
-    let path = os::getcwd();
+    let path = os::getcwd().unwrap();
     let path_s = path.as_str().unwrap();
 
     let mut final_base = base;