Skip to content

Commit bee0abf

Browse files
committed
add a Mutex to prevent concurrent database sync
1 parent 084f676 commit bee0abf

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Cargo.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "waybar-module-pacman-updates"
33
description = "waybar module for Arch to show system updates available"
4-
version = "0.2.2"
4+
version = "0.2.3"
55
edition = "2021"
66
exclude = ["target", "Cargo.lock", "screenshot.png"]
77
readme = "README.md"
@@ -12,3 +12,4 @@ keywords = ["cli", "waybar", "wayland", "linux", "archlinux"]
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15+
lazy_static = "1.4"

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use std::io::Error;
22
use std::process::Command;
3+
use std::sync::Mutex;
34
use std::{thread, time::Duration};
45

6+
lazy_static::lazy_static! {
7+
static ref DATABASE_SYNC_MUTEX: Mutex<()> = Mutex::new(());
8+
}
59
const SLEEP_SECONDS: u16 = 5;
610
const SLEEP_DURATION: Duration = Duration::from_secs(SLEEP_SECONDS as u64);
711

@@ -30,6 +34,7 @@ fn main() -> Result<(), Error> {
3034

3135
// check updates from network
3236
fn sync_database() {
37+
let _lock = DATABASE_SYNC_MUTEX.lock().unwrap();
3338
// checkupdates --nocolor
3439
Command::new("checkupdates")
3540
.args(["--nocolor"])

0 commit comments

Comments
 (0)