diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-07-01 18:00:14 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-02 00:00:14 +0000 |
commit | e746b6d80654ba4e4e26370fe6e4f784ce841d92 (patch) | |
tree | 153ffad92a96126b9ab8e906dcdabf7648755931 /core/normalize_path.rs | |
parent | b9c0e7cd550ab14fa7da7e33ed87cbeeeb9785a0 (diff) |
refactor(core): Extract deno_core (#19658)
`deno_core` is moving out! You'll find it at
https://github.com/denoland/deno_core/ once this PR lands.
Diffstat (limited to 'core/normalize_path.rs')
-rw-r--r-- | core/normalize_path.rs | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/core/normalize_path.rs b/core/normalize_path.rs deleted file mode 100644 index 43af6fea6..000000000 --- a/core/normalize_path.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. - -use std::path::Component; -use std::path::Path; -use std::path::PathBuf; - -/// Normalize all intermediate components of the path (ie. remove "./" and "../" components). -/// Similar to `fs::canonicalize()` but doesn't resolve symlinks. -/// -/// Taken from Cargo -/// <https://github.com/rust-lang/cargo/blob/af307a38c20a753ec60f0ad18be5abed3db3c9ac/src/cargo/util/paths.rs#L60-L85> -#[inline] -pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf { - let mut components = path.as_ref().components().peekable(); - let mut ret = - if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { - components.next(); - PathBuf::from(c.as_os_str()) - } else { - PathBuf::new() - }; - - for component in components { - match component { - Component::Prefix(..) => unreachable!(), - Component::RootDir => { - ret.push(component.as_os_str()); - } - Component::CurDir => {} - Component::ParentDir => { - ret.pop(); - } - Component::Normal(c) => { - ret.push(c); - } - } - } - ret -} |