Use Simplified instead of Normalized for path prefix stripping (#2071)

## Summary

This directly matches the naming of the `dunce` methods.
This commit is contained in:
Charlie Marsh 2024-02-28 20:44:50 -05:00 committed by GitHub
parent f315d07133
commit ef15098288
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 129 additions and 129 deletions

View file

@ -96,7 +96,7 @@ pub async fn write_atomic(path: impl AsRef<Path>, data: impl AsRef<[u8]>) -> std
std::io::ErrorKind::Other,
format!(
"Failed to persist temporary file to {}: {}",
path.normalized_display(),
path.simplified_display(),
err.error
),
)
@ -117,7 +117,7 @@ pub fn write_atomic_sync(path: impl AsRef<Path>, data: impl AsRef<[u8]>) -> std:
std::io::ErrorKind::Other,
format!(
"Failed to persist temporary file to {}: {}",
path.normalized_display(),
path.simplified_display(),
err.error
),
)
@ -229,7 +229,7 @@ impl LockedFile {
warn_user!(
"Waiting to acquire lock for {} (lockfile: {})",
resource,
path.normalized_display(),
path.simplified_display(),
);
file.file().lock_exclusive()?;
Ok(Self(file))

View file

@ -1,25 +1,25 @@
use std::borrow::Cow;
use std::path::Path;
pub trait Normalized {
/// Normalize a [`Path`].
pub trait Simplified {
/// Simplify a [`Path`].
///
/// On Windows, this will strip the `\\?\` prefix from paths. On other platforms, it's a no-op.
fn normalized(&self) -> &Path;
fn simplified(&self) -> &Path;
/// Render a [`Path`] for user-facing display.
///
/// On Windows, this will strip the `\\?\` prefix from paths. On other platforms, it's
/// equivalent to [`std::path::Display`].
fn normalized_display(&self) -> std::path::Display;
fn simplified_display(&self) -> std::path::Display;
}
impl<T: AsRef<Path>> Normalized for T {
fn normalized(&self) -> &Path {
impl<T: AsRef<Path>> Simplified for T {
fn simplified(&self) -> &Path {
dunce::simplified(self.as_ref())
}
fn normalized_display(&self) -> std::path::Display {
fn simplified_display(&self) -> std::path::Display {
dunce::simplified(self.as_ref()).display()
}
}