From b2c8888a501d4cf2679c7af595fa5cb935b06dc6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 25 Oct 2022 11:16:31 -0400 Subject: [PATCH] dir_entry: Implement file_name() for broken symlinks --- src/dir_entry.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dir_entry.rs b/src/dir_entry.rs index 209057e..b934f3b 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -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() }