Skip to content

Commit

Permalink
Consider different paths as independent
Browse files Browse the repository at this point in the history
  • Loading branch information
Pzixel committed Mar 26, 2020
1 parent ca314e0 commit 97678ba
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
use std::sync::mpsc::{channel, Receiver, Sender, TryRecvError};
use std::thread;
use std::time::Duration;
use std::collections::HashMap;

#[cfg(windows)]
fn get_default_path() -> Result<PathBuf, String> {
Expand Down Expand Up @@ -127,7 +128,7 @@ fn run_watch_loop(path: PathBuf, frequency: NonZeroU32, stop_rx: Receiver<()>, s

#[derive(Default)]
struct SaveHandler {
calls: u32,
calls: HashMap<PathBuf, u32>,
}

impl SaveHandler {
Expand All @@ -138,7 +139,8 @@ impl SaveHandler {
) -> Result<(), retry::Error<io::Error>> {
let path = path.as_ref();
println!("{} Handling file {:?}", Local::now().to_rfc3339(), path);
if self.calls % frequency.get() == 0 {
let calls = self.calls.entry(path.into()).or_default();
if *calls % frequency.get() == 0 {
let new_path = get_new_path(path);
println!("{} Copying {:?} to {:?}", Local::now().to_rfc3339(), path, new_path);
retry::retry(retry::delay::Fixed::from_millis(200).take(10), move || {
Expand All @@ -147,7 +149,7 @@ impl SaveHandler {
} else {
println!("{} Skipping saving {:?}: Not time yet", Local::now().to_rfc3339(), path);
}
self.calls += 1;
*calls += 1;
Ok(())
}
}
Expand Down

0 comments on commit 97678ba

Please sign in to comment.