From e28546980b435157a9b3dc880c1801d0bb3891da Mon Sep 17 00:00:00 2001 From: Michael Weirauch Date: Mon, 20 Dec 2021 22:58:26 +0100 Subject: [PATCH] scanner: handle dot-entries Dot-directories will not be recursed into any further, though. Fixes #14. --- README.md | 2 ++ src/scanner.rs | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 117fff6..a30efb8 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ Any skip-spec which matches always wins over a previous ignore-spec match. So wi The supported glob patterns can be found in the [globset](https://docs.rs/globset) project. +> Any dot-directories (e.g. ".git") encountered while scanning will not be recursed into any further and thus no ignore matching will be performed on their contents. Such directories should either be ignored or synced entirely. +> > It is recommended to use the `-n` (dry-run) option when testing new ignore or skip specifications! ### One-time scanning diff --git a/src/scanner.rs b/src/scanner.rs index 9bad7cf..8554761 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -3,7 +3,7 @@ use std::process; use std::sync::mpsc::channel; use std::time::Duration; -use log::{debug, error, info, trace, warn}; +use log::{debug, error, info, warn}; use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; use walkdir::WalkDir; @@ -88,17 +88,6 @@ impl Scanner { } fn handle_entry(&self, path: &Path, dry_run: bool, scanner_stats: &mut ScannerStats) -> bool { - if let Some(file_name) = path.file_name() { - if file_name - .to_str() - .map(|s| s.starts_with('.')) - .unwrap_or(false) - { - trace!("SKIPDOT {:?}", path); - return false; - } - } - let matches = self.matcher.matches(path.to_str().unwrap().to_string()); if matches { if self.dropbox.is_ignored(path) { @@ -119,6 +108,14 @@ impl Scanner { return false; } - true + // don't recurse dot-entries (only effective in "scan" mode) + let recurse = path + .file_name() + .unwrap_or_default() + .to_str() + .map(|s| !s.starts_with('.')) + .unwrap_or(true); + + recurse } }