diff --git a/src/main.rs b/src/main.rs index ac82415..21bf1df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,36 +17,36 @@ fn breadth_first_traverse(prog: &str, roots: Vec, allow_hidden: bool, fo q.push(PathBuf::from("."))?; } else { for root in roots { - q.push(PathBuf::from(root))?; - } - } - - loop { - let path = q.pop()?; - if !follow_links && path.is_symlink() { - continue; - } - if path != dotdir && path != dotdotdir { - if let Some(file_name) = path.file_name() { - if let Some(file_name) = file_name.to_str() { - if !allow_hidden { - if let Some(first_char) = file_name.chars().next() { - if first_char == '.' { - continue; + let path = PathBuf::from(root); + if !follow_links && path.is_symlink() { + continue; + } + if path != dotdir && path != dotdotdir { + if let Some(file_name) = path.file_name() { + if let Some(file_name) = file_name.to_str() { + if !allow_hidden { + if let Some(first_char) = file_name.chars().next() { + if first_char == '.' { + continue; + } } } - } - if ignores.get(file_name).is_some() { - continue; + if ignores.get(file_name).is_some() { + continue; + } + } else { + eprintln!("{}: {}: cannot read filename", prog, path.display()) } } else { - eprintln!("{}: {}: cannot read filename", prog, path.display()) + unreachable!("path ends with \"..\", which should not happen"); } - } else { - unreachable!("path ends with \"..\", which should not happen"); } + q.push(path)?; } + } + loop { + let path = q.pop()?; let entries = fs::read_dir(&path); if let Ok(entries) = entries { for entry in entries {