Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#245] Return non-zero exit code in case of confirmation timeout #246

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions src/bin/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ pub enum ActivationConfirmationError {
CreateConfirmFile(std::io::Error),
#[error("Could not watch for activation sentinel: {0}")]
Watcher(#[from] notify::Error),
#[error("Error waiting for confirmation event: {0}")]
WaitingError(#[from] DangerZoneError),
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -256,7 +258,6 @@ async fn danger_zone(
}

pub async fn activation_confirmation(
profile_path: String,
temp_path: PathBuf,
confirm_timeout: u16,
closure: String,
Expand Down Expand Up @@ -302,18 +303,9 @@ pub async fn activation_confirmation(

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

if let Err(err) = danger_zone(done, confirm_timeout).await {
error!("Error waiting for confirmation event: {}", err);

if let Err(err) = deactivate(&profile_path).await {
error!(
"Error de-activating due to another error waiting for confirmation, oh no...: {}",
err
);
}
}

Ok(())
danger_zone(done, confirm_timeout)
.await
.map_err(|err| ActivationConfirmationError::WaitingError(err))
}

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

if magic_rollback && !boot {
info!("Magic rollback is enabled, setting up confirmation hook...");

match activation_confirmation(profile_path.clone(), temp_path, confirm_timeout, closure)
.await
{
Ok(()) => {}
Err(err) => {
deactivate(&profile_path).await?;
return Err(ActivateError::ActivationConfirmation(err));
}
};
if let Err(err) = activation_confirmation(temp_path, confirm_timeout, closure).await {
deactivate(&profile_path).await?;
return Err(ActivateError::ActivationConfirmation(err));
}
}
}

Expand Down