Skip to content

Commit ba09b78

Browse files
authored
fix: return an error if the activation of tmp files fails (#255)
We want system-manager to return an error if the activation of tmp files fails.
1 parent c64d185 commit ba09b78

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/activate.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,16 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
8282
match etc_files::activate(store_path, old_state.file_tree, ephemeral) {
8383
Ok(etc_tree) => {
8484
log::info!("Activating tmp files...");
85-
match tmp_files::activate(&etc_tree) {
86-
Ok(_) => {
87-
log::debug!("Successfully created tmp files");
88-
}
89-
Err(e) => {
90-
log::error!("Error during activation of tmp files");
91-
log::error!("{e}");
92-
}
93-
};
85+
let tmp_result = tmp_files::activate(&etc_tree);
86+
if let Err(e) = &tmp_result {
87+
log::error!("Error during activation of tmp files");
88+
log::error!("{e}");
89+
} else {
90+
log::debug!("Successfully created tmp files");
91+
}
9492

9593
log::info!("Activating systemd services...");
96-
match services::activate(store_path, old_state.services, ephemeral) {
94+
let final_state = match services::activate(store_path, old_state.services, ephemeral) {
9795
Ok(services) => State {
9896
file_tree: etc_tree,
9997
services,
@@ -105,19 +103,25 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
105103
services: result,
106104
}
107105
}
106+
};
107+
final_state.write_to_file(state_file)?;
108+
109+
if let Err(e) = tmp_result {
110+
return Err(e.into());
108111
}
112+
113+
Ok(())
109114
}
110115
Err(ActivationError::WithPartialResult { result, source }) => {
111116
log::error!("Error during activation: {source:?}");
112-
State {
117+
let final_state = State {
113118
file_tree: result,
114119
..old_state
115-
}
120+
};
121+
final_state.write_to_file(state_file)?;
122+
Ok(())
116123
}
117124
}
118-
.write_to_file(state_file)?;
119-
120-
Ok(())
121125
}
122126

123127
pub fn prepopulate(store_path: &StorePath, ephemeral: bool) -> Result<()> {

0 commit comments

Comments
 (0)