Skip to content

Commit

Permalink
feat(aura): detect the Pacman DB lockfile
Browse files Browse the repository at this point in the history
Closes #918
  • Loading branch information
fosskers committed Aug 24, 2024
1 parent 188ef0e commit 1b5ad94
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

#### Changed

- Installation attempts will now pause if a Pacman database lockfile is detected
(usually found at `/var/lib/pacman/db.lck`). Aura will repeatedly sleep and
reattempt for up to 1 minute before failing; this is to prevent an infinite
loop in scripts.

#### Fixed

- Restore support for `-Qtt`.
Expand Down
2 changes: 1 addition & 1 deletion rust/aura-core/src/aur/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ where
// FIXME Fri Feb 18 2022 Same here as above.
drop(alpm);

debug!("{} is may be an AUR package.", pr);
debug!("{} may be an AUR package.", pr);
let path = pull_or_clone(fetch, clone_d, parent, &pkg)?;
debug!("Parsing .SRCINFO for {}", pkg);
let full = path.join(".SRCINFO");
Expand Down
3 changes: 2 additions & 1 deletion rust/aura-pm/src/command/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub(crate) fn downgrade(
return Err(Error::NothingToDo);
}

crate::pacman::sudo_pacman(env, "-U", NOTHING, to_downgrade).map_err(Error::Pacman)?;
crate::pacman::pacman_install_from_tarball(env, NOTHING, to_downgrade)
.map_err(Error::Pacman)?;
green!(fll, "common-done");
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion rust/aura-pm/src/command/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ fn restore_snapshot(
})
.map(|pp| pp.into_pathbuf().into_os_string());

crate::pacman::sudo_pacman(env, "-U", NOTHING, tarballs).map_err(Error::Pacman)?;
crate::pacman::pacman_install_from_tarball(env, NOTHING, tarballs)
.map_err(Error::Pacman)?;
}

// Remove packages that weren't installed within the chosen snapshot.
Expand Down
5 changes: 5 additions & 0 deletions rust/aura-pm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ impl Env {

Ok(())
}

/// The location of the Pacman database lockfile.
pub(crate) fn lock_file(&self) -> PathBuf {
Path::new(&self.pacman.db_path).join("db.lck")
}
}

#[derive(Debug, Deserialize)]
Expand Down
12 changes: 12 additions & 0 deletions rust/aura-pm/src/pacman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use crate::env::Env;
use crate::error::Nested;
use crate::localization::Localised;
use i18n_embed_fl::fl;
use log::debug;
use log::error;
use std::ffi::OsStr;
use std::process::Command;
use std::time::Duration;

pub(crate) enum Error {
ExternalCmd(std::io::Error),
Expand Down Expand Up @@ -105,6 +107,16 @@ where
S: AsRef<OsStr>,
T: AsRef<OsStr>,
{
let lock = env.lock_file();
let secs = Duration::from_secs(3);
let mut tries = 0;

while lock.exists() && tries < 20 {
tries += 1;
debug!("{} exists. Sleeping... ({})", lock.display(), tries);
std::thread::sleep(secs);
}

sudo_pacman(env, "-U", flags, args).map_err(|_| Error::InstallFromTarball)
}

Expand Down

0 comments on commit 1b5ad94

Please sign in to comment.