From 0677e6331ddc50271ddf44b1e3330d15c333d1ea Mon Sep 17 00:00:00 2001 From: Matthias Reitinger Date: Sat, 14 Oct 2017 02:06:25 +0200 Subject: [PATCH] Fix too many path separators on Windows (#93). --- src/output.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/output.rs b/src/output.rs index dbf562d..4a1ea99 100644 --- a/src/output.rs +++ b/src/output.rs @@ -3,7 +3,7 @@ use internal::{FdOptions, PathDisplay, ROOT_DIR}; use std::{fs, process}; use std::io::{self, Write}; use std::ops::Deref; -use std::path::{self, Path, PathBuf}; +use std::path::{self, Path, PathBuf, Component}; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; @@ -42,6 +42,13 @@ pub fn print_entry(base: &Path, entry: &PathBuf, config: &FdOptions) { component_path.push(Path::new(comp_str.deref())); + if let Component::RootDir = component { + // Printing the root dir would result in too many path separators on Windows. + // Note that a root dir component won't occur on Unix, because `entry` is never an + // absolute path in that case. + continue; + } + let metadata = component_path.metadata().ok(); let is_directory = metadata.as_ref().map(|md| md.is_dir()).unwrap_or(false);