Avoid empty user display paths (#9312)
Currently, user display returns an empty path if the current dir is the directory we are printing. This leads to odd messages such as > Including project.license-files at `` with `LICENSE*` or > Not a license files match: `` Instead, we display the current path as a dot.
This commit is contained in:
@@ -64,6 +64,11 @@ impl<T: AsRef<Path>> Simplified for T {
|
|||||||
return path.display();
|
return path.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if path.as_os_str() == "" {
|
||||||
|
// Avoid printing an empty string for the current directory
|
||||||
|
return Path::new(".").display();
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to strip the current working directory, then the canonicalized current working
|
// Attempt to strip the current working directory, then the canonicalized current working
|
||||||
// directory, in case they differ.
|
// directory, in case they differ.
|
||||||
let path = path.strip_prefix(CWD.simplified()).unwrap_or(path);
|
let path = path.strip_prefix(CWD.simplified()).unwrap_or(path);
|
||||||
@@ -85,6 +90,11 @@ impl<T: AsRef<Path>> Simplified for T {
|
|||||||
.strip_prefix(base.as_ref())
|
.strip_prefix(base.as_ref())
|
||||||
.unwrap_or_else(|_| path.strip_prefix(CWD.simplified()).unwrap_or(path));
|
.unwrap_or_else(|_| path.strip_prefix(CWD.simplified()).unwrap_or(path));
|
||||||
|
|
||||||
|
if path.as_os_str() == "" {
|
||||||
|
// Avoid printing an empty string for the current directory
|
||||||
|
return Path::new(".").display();
|
||||||
|
}
|
||||||
|
|
||||||
path.display()
|
path.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user