Implement EtcTree::update_state
This commit is contained in:
parent
043bd86663
commit
e8e21ee2d5
1 changed files with 49 additions and 35 deletions
|
|
@ -145,7 +145,7 @@ impl EtcTree {
|
||||||
where
|
where
|
||||||
F: Fn(&Path) -> bool,
|
F: Fn(&Path) -> bool,
|
||||||
{
|
{
|
||||||
let new_tree = self.nested.keys().fold(self.clone(), |mut new_tree, name| {
|
let new_tree = self.nested.clone().keys().fold(self, |mut new_tree, name| {
|
||||||
new_tree.nested = new_tree.nested.alter(
|
new_tree.nested = new_tree.nested.alter(
|
||||||
|subtree| subtree.and_then(|subtree| subtree.deactivate(delete_action)),
|
|subtree| subtree.and_then(|subtree| subtree.deactivate(delete_action)),
|
||||||
name.to_owned(),
|
name.to_owned(),
|
||||||
|
|
@ -221,31 +221,41 @@ impl EtcTree {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Remove from this tree all subtrees also contained in the given tree
|
fn update_state<F>(self, other: Self, delete_action: &F) -> Self
|
||||||
// fn diff<F>(&mut self, old: &mut EtcTree, deactivate_action: &F)
|
where
|
||||||
// where
|
F: Fn(&Path) -> bool,
|
||||||
// F: Fn(&str, &mut EtcTree) -> bool,
|
{
|
||||||
// {
|
let to_deactivate = other
|
||||||
// if self.status != old.status {
|
.nested
|
||||||
// self.status = self.status.merge(&old.status);
|
.clone()
|
||||||
// }
|
.relative_complement(self.nested.clone());
|
||||||
//
|
let to_merge = other.nested.clone().intersection(self.nested.clone());
|
||||||
// let keys = old.nested.keys().collect::<HashSet<_>>();
|
|
||||||
// keys.iter().for_each(|key| {
|
let deactivated = to_deactivate.keys().fold(self, |mut new_tree, name| {
|
||||||
// if let Some(subtree) = self.nested.get_mut::<str>(key.as_ref()) {
|
new_tree.nested = new_tree.nested.alter(
|
||||||
// subtree.diff(
|
|subtree| subtree.and_then(|subtree| subtree.deactivate(delete_action)),
|
||||||
// old.nested.get_mut::<str>(key.as_ref()).unwrap(),
|
name.to_owned(),
|
||||||
// deactivate_action,
|
);
|
||||||
// );
|
new_tree
|
||||||
// } else {
|
});
|
||||||
// let deleted =
|
|
||||||
// deactivate_action(key, old.nested.get_mut::<str>(key.as_ref()).unwrap());
|
to_merge.keys().fold(deactivated, |mut new_tree, name| {
|
||||||
// if !deleted {
|
new_tree.nested = new_tree.nested.alter(
|
||||||
// // TODO what can we do here??
|
|subtree| {
|
||||||
// }
|
subtree.and_then(|subtree| {
|
||||||
// }
|
other.nested.get(name).map(|other_tree| {
|
||||||
// });
|
let mut new_tree =
|
||||||
// }
|
subtree.update_state(other_tree.clone(), delete_action);
|
||||||
|
new_tree.status = new_tree.status.merge(&other_tree.status);
|
||||||
|
new_tree
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
name.to_owned(),
|
||||||
|
);
|
||||||
|
new_tree
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
@ -272,16 +282,20 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
|
||||||
|
|
||||||
// TODO: constant?
|
// TODO: constant?
|
||||||
let static_dir_name = ".system-manager-static";
|
let static_dir_name = ".system-manager-static";
|
||||||
let (state, status) =
|
let (state, status) = create_etc_static_link(
|
||||||
create_etc_static_link(static_dir_name, &config.static_env, &etc_dir, old_state);
|
static_dir_name,
|
||||||
|
&config.static_env,
|
||||||
|
&etc_dir,
|
||||||
|
EtcTree::new(PathBuf::new()),
|
||||||
|
);
|
||||||
status?;
|
status?;
|
||||||
let new_state = create_etc_links(config.entries.values(), &etc_dir, state);
|
let new_state = create_etc_links(config.entries.values(), &etc_dir, state).update_state(
|
||||||
|
old_state,
|
||||||
// new_state.diff(&mut old_state, &|name, subtree| {
|
&|path| {
|
||||||
// log::debug!("Deactivating: {name}");
|
log::debug!("Deactivating: {}", path.display());
|
||||||
// false
|
false
|
||||||
// });
|
},
|
||||||
//log::debug!("{old_state}");
|
);
|
||||||
|
|
||||||
serialise_state(&new_state)?;
|
serialise_state(&new_state)?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue