Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/pacman.py
diff options
context:
space:
mode:
authorDaniel <blackrabbit256@gmail.com>2022-02-18 21:33:28 +1100
committerGitHub <noreply@github.com>2022-02-18 11:33:28 +0100
commit4b3b21ed756463914d618abe11345c9839217473 (patch)
tree94fecd8d11262a5423d6af3805f24d63012519b5 /archinstall/lib/pacman.py
parent62a6aec197b0e83ab91fdec1ab15427ecf749dac (diff)
Check if pacman is available (#958)
* Check if pacman is available * Update pacman call * Added a graceful wait to `run_pacman` * Fix flake8 Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com> Co-authored-by: Anton Hvornum <anton.feeds+github@gmail.com>
Diffstat (limited to 'archinstall/lib/pacman.py')
-rw-r--r--archinstall/lib/pacman.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/archinstall/lib/pacman.py b/archinstall/lib/pacman.py
new file mode 100644
index 00000000..9c427aff
--- /dev/null
+++ b/archinstall/lib/pacman.py
@@ -0,0 +1,28 @@
+import logging
+import pathlib
+import time
+
+from .general import SysCommand
+from .output import log
+
+
+def run_pacman(args :str, default_cmd :str = 'pacman') -> SysCommand:
+ """
+ A centralized function to call `pacman` from.
+ It also protects us from colliding with other running pacman sessions (if used locally).
+ The grace period is set to 10 minutes before exiting hard if another pacman instance is running.
+ """
+ pacman_db_lock = pathlib.Path('/var/lib/pacman/db.lck')
+
+ if pacman_db_lock.exists():
+ log(_('Pacman is already running, waiting maximum 10 minutes for it to terminate.'), level=logging.WARNING, fg="red")
+
+ started = time.time()
+ while pacman_db_lock.exists():
+ time.sleep(0.25)
+
+ if time.time() - started > (60 * 10):
+ log(_('Pre-existing pacman lock never exited. Please clean up any existing pacman sessions before using archinstall.'), level=logging.WARNING, fg="red")
+ exit(1)
+
+ return SysCommand(f'{default_cmd} {args}')