Skip to content

Commit

Permalink
scanner: handle dot-entries
Browse files Browse the repository at this point in the history
Dot-directories will not be recursed into any further, though.

Fixes #14.
  • Loading branch information
mweirauch committed Dec 22, 2021
1 parent 6656caf commit c144229
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}

0 comments on commit c144229

Please # to comment.