Skip to content

Commit 514fa3b

Browse files
authored
Merge pull request #246 from serokell/rvem/#245-return-non-zero-exit-code-for-confirmation-timeout
[#245] Return non-zero exit code in case of confirmation timeout
2 parents 660180b + b076e35 commit 514fa3b

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

src/bin/activate.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ pub enum ActivationConfirmationError {
229229
CreateConfirmFile(std::io::Error),
230230
#[error("Could not watch for activation sentinel: {0}")]
231231
Watcher(#[from] notify::Error),
232+
#[error("Error waiting for confirmation event: {0}")]
233+
WaitingError(#[from] DangerZoneError),
232234
}
233235

234236
#[derive(Error, Debug)]
@@ -256,7 +258,6 @@ async fn danger_zone(
256258
}
257259

258260
pub async fn activation_confirmation(
259-
profile_path: String,
260261
temp_path: PathBuf,
261262
confirm_timeout: u16,
262263
closure: String,
@@ -302,18 +303,9 @@ pub async fn activation_confirmation(
302303

303304
watcher.watch(&lock_path, RecursiveMode::NonRecursive)?;
304305

305-
if let Err(err) = danger_zone(done, confirm_timeout).await {
306-
error!("Error waiting for confirmation event: {}", err);
307-
308-
if let Err(err) = deactivate(&profile_path).await {
309-
error!(
310-
"Error de-activating due to another error waiting for confirmation, oh no...: {}",
311-
err
312-
);
313-
}
314-
}
315-
316-
Ok(())
306+
danger_zone(done, confirm_timeout)
307+
.await
308+
.map_err(|err| ActivationConfirmationError::WaitingError(err))
317309
}
318310

319311
#[derive(Error, Debug)]
@@ -463,16 +455,10 @@ pub async fn activate(
463455

464456
if magic_rollback && !boot {
465457
info!("Magic rollback is enabled, setting up confirmation hook...");
466-
467-
match activation_confirmation(profile_path.clone(), temp_path, confirm_timeout, closure)
468-
.await
469-
{
470-
Ok(()) => {}
471-
Err(err) => {
472-
deactivate(&profile_path).await?;
473-
return Err(ActivateError::ActivationConfirmation(err));
474-
}
475-
};
458+
if let Err(err) = activation_confirmation(temp_path, confirm_timeout, closure).await {
459+
deactivate(&profile_path).await?;
460+
return Err(ActivateError::ActivationConfirmation(err));
461+
}
476462
}
477463
}
478464

0 commit comments

Comments
 (0)