Add duplicate domain check, closes #5
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s

This commit is contained in:
Neshura 2024-04-10 23:22:11 +02:00
parent a028d4245b
commit 76a567d1bf
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -146,6 +146,7 @@ impl Config {
let msg = format!("Using {}", path);
directories.push(system_path.to_path_buf());
info!(msg);
Self::check_for_duplicate_domains(&user_config.domain_configs);
Ok((Config {
user: user_config,
system: data,
@ -224,6 +225,32 @@ impl Config {
}
}
}
fn check_for_duplicate_domains(domain_configs: &[DomainLinkConfig]) {
let mut checked_domains: Vec<String> = vec![];
for (cfg_idx, config) in domain_configs.iter().enumerate() {
for (idx, domain) in config.domains.iter().enumerate() {
if !checked_domains.contains(domain) {
if config.domains[idx+1..].contains(domain) {
// Error
let msg = format!("Duplicate Domain use detected for '{domain}");
warn!(msg);
checked_domains.push(domain.clone());
}
else {
for d in domain_configs[cfg_idx+1..].iter() {
if d.domains.contains(domain) {
let msg = format!("Duplicate Domain use detected for '{domain}");
warn!(msg);
checked_domains.push(domain.clone());
break;
}
}
}
}
}
}
}
}
#[actix_web::main]