diff options
author | Paul Holzinger <pholzing@redhat.com> | 2024-07-31 11:04:46 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2024-07-31 18:39:12 +0200 |
commit | 6bb82d625a8ad43c1a0f3307acb783ce35d2368b (patch) | |
tree | ea44cbc84b3d00f3c82fa587d76c7d0c59f44ca3 | |
parent | 0855124bc9c56dd87acaabf16bfb489316e948f4 (diff) |
config: ignore enoent errors while reading configs
When we list files in directory there is a race where the file might
have been removed in the meantime. So ignore the ENOENT case as this is
no real error and we still want to parse the other files.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r-- | src/config/mod.rs | 22 | ||||
-rw-r--r-- | src/test/test.rs | 7 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index c49b344..9db86f3 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,6 +1,6 @@ use crate::backend::DNSBackend; use crate::error::{AardvarkError, AardvarkResult}; -use log::warn; +use log::error; use std::collections::HashMap; use std::fs::{metadata, read_dir, read_to_string}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; @@ -64,7 +64,19 @@ pub fn parse_configs( continue; } } - let parsed_network_config = parse_config(cfg.path().as_path())?; + let parsed_network_config = match parse_config(cfg.path().as_path()) { + Ok(c) => c, + Err(e) => { + if e.kind() != std::io::ErrorKind::NotFound { + error!( + "Error reading config file {:?} for server update: {}", + cfg.path(), + e + ) + } + continue; + } + }; let mut internal = false; @@ -171,7 +183,11 @@ pub fn parse_configs( network_is_internal.insert(network_name.clone(), internal); } } - Err(e) => warn!("Error reading config file for server update: {}", e), + Err(e) => { + if e.kind() != std::io::ErrorKind::NotFound { + error!("Error listing config file for server update: {}", e) + } + } } } diff --git a/src/test/test.rs b/src/test/test.rs index 8cb7eaa..2fda36d 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -55,12 +55,9 @@ mod tests { } } #[test] - // Parse bad config files must fail + // Parse bad config files should not hard error fn test_parsing_bad_config_files() { - match parse_configs("src/test/config/podman_bad_config") { - Ok((_, _, _)) => panic!("parsing bad config must fail"), - Err(_) => {} - } + parse_configs("src/test/config/podman_bad_config").expect("config parsing failed"); } /* -------------------------------------------- */ // -------Verify backend custom dns server ---- |