Skip to content

Commit

Permalink
Add debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed May 9, 2024
1 parent 0ebe593 commit e09fe28
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ use std::path::{Component, Path, PathBuf};

use once_cell::sync::Lazy;

pub static CWD: Lazy<PathBuf> = Lazy::new(|| {
/// The current working directory.
pub static CWD: Lazy<PathBuf> =
Lazy::new(|| std::env::current_dir().expect("The current directory must exist"));

/// The current working directory, canonicalized.
pub static CANONICAL_CWD: Lazy<PathBuf> = Lazy::new(|| {
std::env::current_dir()
.unwrap()
.canonicalize()
.expect("The current directory must exist")
.canonicalize()
.expect("The current directory must be canonicalized")
});

pub trait Simplified {
Expand Down Expand Up @@ -46,8 +51,14 @@ impl<T: AsRef<Path>> Simplified for T {

fn user_display(&self) -> std::path::Display {
let path = dunce::simplified(self.as_ref());

// Attempt to strip the current working directory, then the canonicalized current working
// directory, in case they differ.
path.strip_prefix(CWD.simplified())
.unwrap_or(path)
.unwrap_or_else(|_| {
path.strip_prefix(CANONICAL_CWD.simplified())
.unwrap_or(path)
})
.display()
}
}
Expand Down

0 comments on commit e09fe28

Please sign in to comment.