unified merge
All checks were successful
Version Check / check-version (pull_request) Successful in 3s

This commit is contained in:
2026-03-18 16:44:59 +01:00
parent b88d93c800
commit b8c49d4c13
6 changed files with 55 additions and 161 deletions

View File

@@ -10,7 +10,6 @@ pub mod properties;
pub enum ItemStatus {
Present,
MissingFromActive,
MissingFromTemplate,
Modified,
}
@@ -48,7 +47,41 @@ pub enum FormatType {
pub trait FormatHandler {
fn parse(&self, path: &Path) -> io::Result<Vec<ConfigItem>>;
fn merge(&self, path: &Path, vars: &mut Vec<ConfigItem>) -> io::Result<()>;
fn merge(&self, path: &Path, vars: &mut Vec<ConfigItem>) -> io::Result<()> {
if !path.exists() {
return Ok(());
}
let template_vars = self.parse(path).unwrap_or_default();
for var in vars.iter_mut() {
if let Some(template_var) = template_vars.iter().find(|v| v.path == var.path) {
var.template_value = template_var.value.clone();
var.default_value = template_var.value.clone();
if var.value != template_var.value {
var.status = ItemStatus::Modified;
} else {
var.status = ItemStatus::Present;
}
} else {
// Exists in active, but not in template
var.status = ItemStatus::Present;
}
}
// Add items from template that are missing in active
for template_var in template_vars {
if !vars.iter().any(|v| v.path == template_var.path) {
let mut new_item = template_var.clone();
new_item.status = ItemStatus::MissingFromActive;
new_item.value = None;
vars.push(new_item);
}
}
Ok(())
}
fn write(&self, path: &Path, vars: &[ConfigItem]) -> io::Result<()>;
}