diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-10-30 02:19:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-30 03:19:03 +0100 |
commit | 6be6c517d0691bf1d14eef67668e575c84cdfdf4 (patch) | |
tree | fd6b37f2807f78325a08fff5e34166d6eec84ca7 /cli/fs.rs | |
parent | 1854c6f73be9d4439807911ce9cba1125af93dd4 (diff) |
fix(cli/fmt): Strip "\\?\" prefix when displaying Windows paths (#8135)
Diffstat (limited to 'cli/fs.rs')
-rw-r--r-- | cli/fs.rs | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -4,7 +4,7 @@ use deno_core::error::AnyError; pub use deno_core::normalize_path; use std::env::current_dir; use std::fs::OpenOptions; -use std::io::Write; +use std::io::{Error, Write}; use std::path::{Path, PathBuf}; use walkdir::WalkDir; @@ -47,6 +47,20 @@ pub fn write_file_2<T: AsRef<[u8]>>( file.write_all(data.as_ref()) } +/// Similar to `std::fs::canonicalize()` but strips UNC prefixes on Windows. +pub fn canonicalize_path(path: &Path) -> Result<PathBuf, Error> { + let mut canonicalized_path = path.canonicalize()?; + if cfg!(windows) { + canonicalized_path = PathBuf::from( + canonicalized_path + .display() + .to_string() + .trim_start_matches("\\\\?\\"), + ); + } + Ok(canonicalized_path) +} + pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> { let resolved_path = if path.is_absolute() { path.to_owned() |