Only forcibly attempt to call trans_release
upon an error
- Up until this point, attempting to release a transaction via a call to `trans_release` was done liberally and unnecessarily so; this has now been fixed. - Added whitespace character in `aggregator` module to println statement. - Renamed `NoCompatibleRemotes` to `NoCompatibleContainers` in the `SyncError` error enum.
This commit is contained in:
parent
828da40579
commit
47dfcc8fc4
4 changed files with 22 additions and 28 deletions
|
@ -82,7 +82,7 @@ pub enum SyncError {
|
|||
TransactionFailure(String),
|
||||
InitializationFailure(String),
|
||||
InternalError(String),
|
||||
NoCompatibleRemotes,
|
||||
NoCompatibleContainers,
|
||||
UnableToLocateKeyrings,
|
||||
RepoConfError(String, String),
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ impl Display for SyncError {
|
|||
Self::TransactionAgentError | Self::TransactionAgentFailure =>
|
||||
write!(fmter, "Agent process terminated due to upstream error."),
|
||||
Self::RecursionDepthExceeded(u) => write!(fmter, "Recursion depth exceeded maximum of {}{u}{}.", *BOLD, *RESET),
|
||||
Self::NoCompatibleRemotes => write!(fmter, "No compatible containers available to synchronize remote database."),
|
||||
Self::NoCompatibleContainers => write!(fmter, "No compatible containers available to synchronize remote database."),
|
||||
Self::InvalidMagicNumber => write!(fmter, "Deserialization of input parameters failed: Invalid magic number."),
|
||||
Self::TargetNotInstalled(pkg) => write!(fmter, "Target package {}{pkg}{}: Not installed.", *BOLD, *RESET),
|
||||
Self::InitializationFailure(msg) => write!(fmter, "Failure to initialize transaction: {msg}"),
|
||||
|
@ -342,7 +342,7 @@ fn register_remote(mut handle: Alpm, config: &AlpmConfigData) -> Alpm {
|
|||
fn synchronize_database(ag: &mut TransactionAggregator, force: bool) -> Result<()> {
|
||||
let handle = match ag.cache().obtain_base_handle() {
|
||||
Some(handle) => handle,
|
||||
None => err!(SyncError::NoCompatibleRemotes)?,
|
||||
None => err!(SyncError::NoCompatibleContainers)?,
|
||||
};
|
||||
let flags = ag.flags();
|
||||
let db_path = format!("{}/pacman/", *DATA_DIR);
|
||||
|
@ -356,7 +356,7 @@ fn synchronize_database(ag: &mut TransactionAggregator, force: bool) -> Result<(
|
|||
err!(SyncError::InitializationFailure(err.to_string()))?
|
||||
}
|
||||
|
||||
Alpm::release(handle).expect("Release Alpm handle");
|
||||
handle.release().generic()?;
|
||||
ag.lock()?.assert()?;
|
||||
|
||||
for handle in ag.cache().filter_handle(vec![Base, Slice, Aggregate]).iter() {
|
||||
|
|
|
@ -225,7 +225,7 @@ impl TransactionType {
|
|||
progress.set_message(format!("{}{}{} ", *BOLD, message, *RESET));
|
||||
progress.tick();
|
||||
} else {
|
||||
println!("{}{}{}{}", *BAR_CYAN, *BOLD, message, *RESET);
|
||||
println!("{} {}{}{}", *BAR_CYAN, *BOLD, message, *RESET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -531,11 +531,7 @@ impl<'a> TransactionHandle<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn release(mut self) {
|
||||
if let Some(alpm) = self.alpm.as_mut() {
|
||||
alpm.trans_release().ok();
|
||||
}
|
||||
|
||||
pub fn release(self) {
|
||||
drop(self);
|
||||
}
|
||||
|
||||
|
@ -548,11 +544,11 @@ impl<'a> TransactionHandle<'a> {
|
|||
}
|
||||
|
||||
pub fn alpm_mut(&mut self) -> &mut Alpm {
|
||||
self.alpm.as_mut().unwrap()
|
||||
self.alpm.as_mut().expect("ALPM handle")
|
||||
}
|
||||
|
||||
pub fn alpm(&self) -> &Alpm {
|
||||
self.alpm.as_ref().unwrap()
|
||||
self.alpm.as_ref().expect("ALPM handle")
|
||||
}
|
||||
|
||||
pub fn set_alpm(&mut self, alpm: Option<Alpm>) {
|
||||
|
|
|
@ -285,6 +285,10 @@ impl<'a> TransactionAggregator<'a> {
|
|||
progress.finish();
|
||||
}
|
||||
|
||||
if let Some(ref mut alpm) = handle.alpm {
|
||||
alpm.trans_release().ok();
|
||||
}
|
||||
|
||||
handle.release();
|
||||
return match err.downcast::<SyncError>().map_err(|err| error!(SyncError::from(err)))? {
|
||||
SyncError::TransactionAgentFailure
|
||||
|
|
|
@ -47,6 +47,7 @@ use crate::{
|
|||
},
|
||||
utils::prompt::prompt,
|
||||
Error,
|
||||
ErrorGeneric,
|
||||
Result,
|
||||
};
|
||||
|
||||
|
@ -78,7 +79,7 @@ impl Transaction for Commit {
|
|||
let state = self.state.as_str();
|
||||
|
||||
if let SyncState::NotRequired = handle.trans_ready(ag.action(), ag.flags())? {
|
||||
return Ok(match ready_state(handle, ag.action(), &self.state) {
|
||||
return Ok(match ready_state(ag.action(), &self.state) {
|
||||
Some(state) => state,
|
||||
None => TransactionState::Complete(false),
|
||||
});
|
||||
|
@ -105,7 +106,7 @@ impl Transaction for Commit {
|
|||
handle.set_alpm(Some(sync::instantiate_alpm(inshandle, ag.flags())?));
|
||||
handle.apply_configuration(inshandle, ag.flags().intersects(TransactionFlags::CREATE))?;
|
||||
ag.logger().log(Info, &format!("container {instance}'s {state} transaction complete"))?;
|
||||
Ok(next_state(handle, ag.action(), &self.state, true))
|
||||
Ok(next_state(ag.action(), &self.state, true))
|
||||
}
|
||||
|
||||
fn debug(&self) -> String {
|
||||
|
@ -135,7 +136,8 @@ fn confirm(
|
|||
println!("{}", sum);
|
||||
|
||||
if ag.flags().contains(TransactionFlags::PREVIEW) {
|
||||
return Ok(State::Next(next_state(handle, ag.action(), state, false)));
|
||||
handle.alpm_mut().trans_release().generic()?;
|
||||
return Ok(State::Next(next_state(ag.action(), state, false)));
|
||||
}
|
||||
|
||||
if !ag.flags().contains(TransactionFlags::NO_CONFIRM) {
|
||||
|
@ -143,23 +145,17 @@ fn confirm(
|
|||
let query = format!("Proceed with {action}?");
|
||||
|
||||
if !prompt("::", format!("{}{query}{}", *BOLD, *RESET), true)? {
|
||||
return Ok(State::Next(next_state(handle, ag.action(), state, false)));
|
||||
handle.alpm_mut().trans_release().generic()?;
|
||||
return Ok(State::Next(next_state(ag.action(), state, false)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle.alpm_mut().trans_release().ok();
|
||||
handle.alpm_mut().trans_release().generic()?;
|
||||
Ok(State::Commit(sum.download()))
|
||||
}
|
||||
|
||||
fn next_state(
|
||||
handle: &mut TransactionHandle,
|
||||
action: &TransactionType,
|
||||
state: &TransactionState,
|
||||
updated: bool,
|
||||
) -> TransactionState {
|
||||
handle.alpm_mut().trans_release().ok();
|
||||
|
||||
fn next_state(action: &TransactionType, state: &TransactionState, updated: bool) -> TransactionState {
|
||||
match action {
|
||||
Remove(..) => match state {
|
||||
CommitForeign => Complete(updated),
|
||||
|
@ -174,9 +170,7 @@ fn next_state(
|
|||
}
|
||||
}
|
||||
|
||||
fn ready_state(handle: &mut TransactionHandle, action: &TransactionType, state: &TransactionState) -> Option<TransactionState> {
|
||||
handle.alpm_mut().trans_release().ok();
|
||||
|
||||
fn ready_state(action: &TransactionType, state: &TransactionState) -> Option<TransactionState> {
|
||||
match action {
|
||||
Remove(..) => match state {
|
||||
CommitForeign => None,
|
||||
|
|
Loading…
Add table
Reference in a new issue