mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-17 09:28:25 +01:00
dir_entry: Implement file_name() for broken symlinks
This commit is contained in:
parent
f0c50befce
commit
b2c8888a50
1 changed files with 9 additions and 1 deletions
|
@ -121,7 +121,15 @@ impl Colorable for DirEntry {
|
|||
fn file_name(&self) -> OsString {
|
||||
let name = match &self.inner {
|
||||
DirEntryInner::Normal(e) => e.file_name(),
|
||||
DirEntryInner::BrokenSymlink(_) => todo!(),
|
||||
DirEntryInner::BrokenSymlink(path) => {
|
||||
// Path::file_name() only works if the last component is Normal,
|
||||
// but we want it for all component types, so we open code it.
|
||||
// Copied from LsColors::style_for_path_with_metadata().
|
||||
path.components()
|
||||
.last()
|
||||
.map(|c| c.as_os_str())
|
||||
.unwrap_or_else(|| path.as_os_str())
|
||||
}
|
||||
};
|
||||
name.to_owned()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue