Skip to content

Commit

Permalink
Print . and .. components properly
Browse files Browse the repository at this point in the history
`Path.file_name()` returns `None` if the path ends in `.` or `..`, which
causes e.g. `exa -d ..` to print a blank line.
  • Loading branch information
Kevin Ballard committed Apr 27, 2017
1 parent 3087565 commit dd63774
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};

Expand Down Expand Up @@ -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(),
};

Expand Down

0 comments on commit dd63774

Please sign in to comment.