3 releases (breaking)

0.3.0 Jul 29, 2024
0.2.0 Jul 13, 2024
0.1.0 May 21, 2023

#430 in Filesystem

Download history 2321/week @ 2024-07-29 1637/week @ 2024-08-05 535/week @ 2024-08-12 621/week @ 2024-08-19 727/week @ 2024-08-26 1387/week @ 2024-09-02 1042/week @ 2024-09-09 513/week @ 2024-09-16 930/week @ 2024-09-23 574/week @ 2024-09-30 427/week @ 2024-10-07 529/week @ 2024-10-14 505/week @ 2024-10-21 418/week @ 2024-10-28 350/week @ 2024-11-04 1958/week @ 2024-11-11

3,281 downloads per month
Used in 6 crates (via breezyshim)

Apache-2.0

20KB
383 lines

Opportunistic dirty file tracker

This library provides a simple way to track dirty files in a directory. It uses the notify crate to watch for file system events and keep track of the files that have been modified.

If the underlying file system does not support watching for file system events, or if there are too many files to watch, the tracker will simply give up and return State::Unknown.

Example:

use dirty_tracker::{State, DirtyTracker};

let td = tempfile::tempdir().unwrap();

let mut tracker = DirtyTracker::new(td.path()).unwrap();
assert_eq!(tracker.state(), State::Clean);
assert!(tracker.paths().unwrap().is_empty());

// Modify a file in the directory.
std::fs::write(td.path().join("file"), b"hello").unwrap();

assert_eq!(tracker.state(), State::Dirty);
assert_eq!(tracker.paths(), Some(&maplit::hashset![td.path().join("file")]));

lib.rs:

Opportunistic dirty file tracker

This library provides a simple way to track dirty files in a directory. It uses the notify crate to watch for file system events and keep track of the files that have been modified.

If the underlying file system does not support watching for file system events, or if there are too many files to watch, the tracker will simply give up and return State::Unknown.

Example

use dirty_tracker::{State, DirtyTracker};

let td = tempfile::tempdir().unwrap();

let mut tracker = DirtyTracker::new(td.path()).unwrap();
assert_eq!(tracker.state(), State::Clean);
assert!(tracker.paths().unwrap().is_empty());

// Modify a file in the directory.
std::fs::write(td.path().join("file"), b"hello").unwrap();

assert_eq!(tracker.state(), State::Dirty);
assert_eq!(tracker.paths(), Some(&maplit::hashset![td.path().join("file")]));

Dependencies

~2–11MB
~128K SLoC