Skip to content

Commit

Permalink
fix: Make config watcher recursive.
Browse files Browse the repository at this point in the history
Signed-off-by: ifuryst <[email protected]>
  • Loading branch information
iFurySt committed Aug 8, 2024
1 parent aab836b commit 06f4ff4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.d/20996_recursive_config_watcher.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes an issue where the configuration watcher did not properly handle recursive directories, ensuring configuration will be reloaded in the automatic-namespacing scenario.

authors: ifuryst
21 changes: 20 additions & 1 deletion src/config/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn create_watcher(
#[cfg(unix)]
fn add_paths(watcher: &mut RecommendedWatcher, config_paths: &[PathBuf]) -> Result<(), Error> {
for path in config_paths {
watcher.watch(path, RecursiveMode::NonRecursive)?;
watcher.watch(path, RecursiveMode::Recursive)?;
}
Ok(())
}
Expand Down Expand Up @@ -199,4 +199,23 @@ mod tests {
panic!("Test timed out");
}
}

#[tokio::test]
async fn recursive_directory_file_update() {
trace_init();

let delay = Duration::from_secs(3);
let dir = temp_dir().to_path_buf();
let sub_dir = dir.join("sources");
let file_path = sub_dir.join("input.toml");

std::fs::create_dir_all(&sub_dir).unwrap();
let mut file = File::create(&file_path).unwrap();

spawn_thread(&[sub_dir], delay).unwrap();

if !test(&mut file, delay * 5).await {
panic!("Test timed out");
}
}
}

0 comments on commit 06f4ff4

Please sign in to comment.