Skip to content

Commit

Permalink
Wait for pacman when db is locked
Browse files Browse the repository at this point in the history
Fixes #282
  • Loading branch information
Morganamilo committed Mar 20, 2021
1 parent f614862 commit 57d73db
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ fn update_sudo<S: AsRef<OsStr>>(sudo: &str, flags: &[S]) -> Result<()> {
Ok(())
}

fn wait_for_lock(config: &Config) {
let path = Path::new(config.alpm.dbpath()).join("db.lck");
let c = config.color;
if path.exists() {
println!(
"{} {}",
c.error.paint("::"),
c.bold.paint("Pacman is currently in use, please wait...")
);

std::thread::sleep(Duration::from_secs(3));
while path.exists() {
std::thread::sleep(Duration::from_secs(3));
}
}
}

pub fn pacman<S: AsRef<str> + Display + std::fmt::Debug>(
config: &Config,
args: &Args<S>,
Expand All @@ -86,6 +103,10 @@ pub fn pacman<S: AsRef<str> + Display + std::fmt::Debug>(
Command::new(args.bin.as_ref())
};

if config.need_root {
wait_for_lock(config);
}

let ret = command
.args(args.args())
.status()
Expand Down

0 comments on commit 57d73db

Please sign in to comment.