diff --git a/src/scan.rs b/src/scan.rs index d0323ec..2fa6b00 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -1,4 +1,3 @@ -use std::ffi::OsStr; use std::io; use std::fs; use std::path::{Path, PathBuf}; @@ -60,11 +59,16 @@ pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec) -> io::Result<()> { Ok(()) } -pub fn scan_dir(path: &Path, entries: &mut Vec, excludes: &mut Vec, stats: &mut Stats) -> io::Result<()> { +pub fn scan_dir(dir: &Path, entries: &mut Vec, excludes: &mut Vec, stats: &mut Stats) -> io::Result<()> { stats.visited_folders += 1; - 'entry: for entry in fs::read_dir(path)? { + let mut gitignore = dir.to_path_buf().clone(); + gitignore.push(".gitignore"); + + if gitignore.exists() { + add_excludes_from_gitignore(&dir.to_path_buf(), excludes); + } + + 'entry: for entry in fs::read_dir(dir)? { let entry = entry?; let path = entry.path(); if path.components().last().unwrap().as_os_str().to_string_lossy().starts_with('.') { - if path.file_name().unwrap() == OsStr::new(".gitignore") { - add_excludes_from_gitignore(&path.parent().unwrap().to_path_buf(), excludes); - } - continue; }