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.
This commit is contained in:
Jean-François Roche 2025-08-21 00:23:50 +02:00 committed by GitHub
parent c64d185d2c
commit ba09b781b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -82,18 +82,16 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
match etc_files::activate(store_path, old_state.file_tree, ephemeral) { match etc_files::activate(store_path, old_state.file_tree, ephemeral) {
Ok(etc_tree) => { Ok(etc_tree) => {
log::info!("Activating tmp files..."); log::info!("Activating tmp files...");
match tmp_files::activate(&etc_tree) { let tmp_result = tmp_files::activate(&etc_tree);
Ok(_) => { if let Err(e) = &tmp_result {
log::debug!("Successfully created tmp files"); log::error!("Error during activation of tmp files");
} log::error!("{e}");
Err(e) => { } else {
log::error!("Error during activation of tmp files"); log::debug!("Successfully created tmp files");
log::error!("{e}"); }
}
};
log::info!("Activating systemd services..."); log::info!("Activating systemd services...");
match services::activate(store_path, old_state.services, ephemeral) { let final_state = match services::activate(store_path, old_state.services, ephemeral) {
Ok(services) => State { Ok(services) => State {
file_tree: etc_tree, file_tree: etc_tree,
services, services,
@ -105,19 +103,25 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
services: result, services: result,
} }
} }
};
final_state.write_to_file(state_file)?;
if let Err(e) = tmp_result {
return Err(e.into());
} }
Ok(())
} }
Err(ActivationError::WithPartialResult { result, source }) => { Err(ActivationError::WithPartialResult { result, source }) => {
log::error!("Error during activation: {source:?}"); log::error!("Error during activation: {source:?}");
State { let final_state = State {
file_tree: result, file_tree: result,
..old_state ..old_state
} };
final_state.write_to_file(state_file)?;
Ok(())
} }
} }
.write_to_file(state_file)?;
Ok(())
} }
pub fn prepopulate(store_path: &StorePath, ephemeral: bool) -> Result<()> { pub fn prepopulate(store_path: &StorePath, ephemeral: bool) -> Result<()> {