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:
parent
09e2ad13d0
commit
6f422c4c05
12 changed files with 56 additions and 43 deletions
|
|
@ -26,7 +26,7 @@ use std::path::Path;
|
|||
|
||||
fn main() {
|
||||
let my_args = os::args();
|
||||
let my_cwd = os::getcwd();
|
||||
let my_cwd = os::getcwd().unwrap();
|
||||
let my_env = os::env();
|
||||
let my_path = Path::new(os::self_exe_name().unwrap());
|
||||
let my_dir = my_path.dir_path();
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ fn test_rm_tempdir_close() {
|
|||
// to depend on std
|
||||
fn recursive_mkdir_rel() {
|
||||
let path = Path::new("frob");
|
||||
let cwd = os::getcwd();
|
||||
let cwd = os::getcwd().unwrap();
|
||||
println!("recursive_mkdir_rel: Making: {} in cwd {} [{}]", path.display(),
|
||||
cwd.display(), path.exists());
|
||||
fs::mkdir_recursive(&path, io::USER_RWX);
|
||||
|
|
@ -141,7 +141,7 @@ fn recursive_mkdir_dot() {
|
|||
|
||||
fn recursive_mkdir_rel_2() {
|
||||
let path = Path::new("./frob/baz");
|
||||
let cwd = os::getcwd();
|
||||
let cwd = os::getcwd().unwrap();
|
||||
println!("recursive_mkdir_rel_2: Making: {} in cwd {} [{}]", path.display(),
|
||||
cwd.display(), path.exists());
|
||||
fs::mkdir_recursive(&path, io::USER_RWX);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue