From dd63774e37691badb446cb71950ba0d2d18146a3 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 25 Apr 2017 15:33:57 -0700 Subject: [PATCH] Print . and .. components properly `Path.file_name()` returns `None` if the path ends in `.` or `..`, which causes e.g. `exa -d ..` to print a blank line. --- src/fs/file.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index 8a19ba1..2a047c3 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -102,8 +102,8 @@ impl<'dir> File<'dir> { /// Create a new File object from the given metadata result, and other data. pub fn with_metadata(metadata: fs::Metadata, path: &Path, parent: Option<&'dir Dir>) -> File<'dir> { - let filename = match path.file_name() { - Some(name) => name.to_string_lossy().to_string(), + let filename = match path.components().next_back() { + Some(comp) => comp.as_os_str().to_string_lossy().to_string(), None => String::new(), }; @@ -174,8 +174,8 @@ impl<'dir> File<'dir> { None => path }; - let filename = match target_path.file_name() { - Some(name) => name.to_string_lossy().to_string(), + let filename = match target_path.components().next_back() { + Some(comp) => comp.as_os_str().to_string_lossy().to_string(), None => String::new(), };