diff options
author | Nayeem Rahman <muhammed.9939@gmail.com> | 2020-01-20 14:45:44 +0000 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2020-01-20 09:45:44 -0500 |
commit | 7f80f9db3f4c3b064b230adfec7ff958fc195da6 (patch) | |
tree | bda74057420a1b51ce293918b6e67123715ee945 /cli/fs.rs | |
parent | 60b53fd6b6dc2af83a64c332b9f3a1926f43d631 (diff) |
refactor: Improve path handling in permission checks (#3714)
Diffstat (limited to 'cli/fs.rs')
-rw-r--r-- | cli/fs.rs | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -129,11 +129,9 @@ pub fn chown(_path: &str, _uid: u32, _gid: u32) -> Result<(), ErrBox> { Err(crate::deno_error::op_not_implemented()) } -pub fn resolve_from_cwd(path: &str) -> Result<(PathBuf, String), ErrBox> { - let candidate_path = Path::new(path); - - let resolved_path = if candidate_path.is_absolute() { - candidate_path.to_owned() +pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, ErrBox> { + let resolved_path = if path.is_absolute() { + path.to_owned() } else { let cwd = std::env::current_dir().unwrap(); cwd.join(path) @@ -155,9 +153,7 @@ pub fn resolve_from_cwd(path: &str) -> Result<(PathBuf, String), ErrBox> { .to_file_path() .expect("URL from a path should contain a valid path"); - let path_string = normalized_path.to_str().unwrap().to_string(); - - Ok((normalized_path, path_string)) + Ok(normalized_path) } #[cfg(test)] @@ -167,19 +163,19 @@ mod tests { #[test] fn resolve_from_cwd_child() { let cwd = std::env::current_dir().unwrap(); - assert_eq!(resolve_from_cwd("a").unwrap().0, cwd.join("a")); + assert_eq!(resolve_from_cwd(Path::new("a")).unwrap(), cwd.join("a")); } #[test] fn resolve_from_cwd_dot() { let cwd = std::env::current_dir().unwrap(); - assert_eq!(resolve_from_cwd(".").unwrap().0, cwd); + assert_eq!(resolve_from_cwd(Path::new(".")).unwrap(), cwd); } #[test] fn resolve_from_cwd_parent() { let cwd = std::env::current_dir().unwrap(); - assert_eq!(resolve_from_cwd("a/..").unwrap().0, cwd); + assert_eq!(resolve_from_cwd(Path::new("a/..")).unwrap(), cwd); } // TODO: Get a good expected value here for Windows. @@ -187,6 +183,6 @@ mod tests { #[test] fn resolve_from_cwd_absolute() { let expected = Path::new("/a"); - assert_eq!(resolve_from_cwd("/a").unwrap().0, expected); + assert_eq!(resolve_from_cwd(expected).unwrap(), expected); } } |