Skip to content

Commit

Permalink
replace is_windows_raw_path with dunce as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Feb 16, 2023
1 parent 2fe4241 commit c5285d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
20 changes: 6 additions & 14 deletions crates/turbo-tasks-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use std::{
use anyhow::{anyhow, bail, Context, Result};
use auto_hash_map::AutoMap;
use bitflags::bitflags;
use dunce::simplified;
use glob::GlobVc;
use invalidator_map::InvalidatorMap;
use jsonc_parser::{parse_to_serde_value, ParseOptions};
Expand All @@ -58,8 +59,6 @@ use turbo_tasks_hash::hash_xxh3_hash64;
use util::{join_path, normalize_path, sys_to_unix, unix_to_sys};

use self::{json::UnparseableJson, mutex_map::MutexMap};
#[cfg(target_family = "windows")]
use crate::util::is_windows_raw_path;
use crate::{
attach::AttachedFileSystemVc,
retry::{retry_blocking, retry_future},
Expand Down Expand Up @@ -271,7 +270,7 @@ impl DiskFileSystem {

pub async fn to_sys_path(&self, fs_path: FileSystemPathVc) -> Result<PathBuf> {
// just in case there's a windows unc path prefix we remove it with `dunce`
let path = dunce::simplified(Path::new(&self.root));
let path = simplified(Path::new(&self.root));
let fs_path = fs_path.await?;
Ok(if fs_path.path.is_empty() {
path.to_path_buf()
Expand Down Expand Up @@ -420,18 +419,11 @@ impl FileSystem for DiskFileSystem {
// strip the root from the path, it serves two purpose
// 1. ensure the linked path is under the root
// 2. strip the root path if the linked path is absolute
#[cfg(target_family = "windows")]
let result = {
let root_path = Path::new(&self.root);
if is_windows_raw_path(root_path) && !is_windows_raw_path(&file) {
file.strip_prefix(Path::new(&self.root[4..]))
} else {
file.strip_prefix(root_path)
}
};
//
// we use `dunce::simplify` to strip a potential UNC prefix on windows, on any
// other OS this gets compiled away
let result = simplified(&file).strip_prefix(simplified(Path::new(&self.root)));

#[cfg(not(target_family = "windows"))]
let result = file.strip_prefix(Path::new(&self.root));
let relative_to_root_path = match result {
Ok(file) => PathBuf::from(sys_to_unix(&file.to_string_lossy()).as_ref()),
Err(_) => return Ok(LinkContent::Invalid.cell()),
Expand Down
15 changes: 0 additions & 15 deletions crates/turbo-tasks-fs/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::borrow::Cow;
#[cfg(target_family = "windows")]
use std::path::Path;

/// Joins two /-separated paths into a normalized path.
/// Paths are concatenated with /.
Expand Down Expand Up @@ -112,16 +110,3 @@ pub fn normalize_request(str: &str) -> String {
}
seqments.join("/")
}

#[cfg(target_family = "windows")]
/// Checks if the path has the `\\?\` prefix which "tells the Windows APIs to
/// disable all string parsing and to send the string that follows it straight
/// to the file system."
///
/// See [Win32 File Namespaces](https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces)
pub fn is_windows_raw_path(path: impl AsRef<Path>) -> bool {
// `Path::new("\\\\?\\D:\\workspace\\turbo-tooling").starts_with("\\\\?\\")` is
// `false`.
// So we use `String::starts_with` here
path.as_ref().to_string_lossy().starts_with("\\\\?\\")
}

0 comments on commit c5285d8

Please sign in to comment.