From f95a66c7ea65390eadab2783041131a8024711a6 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 27 Jan 2021 17:25:13 +0800 Subject: [PATCH] support pacman -Scc --- src/pacroller/config.json.example | 3 ++- src/pacroller/config.py | 2 ++ src/pacroller/main.py | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pacroller/config.json.example b/src/pacroller/config.json.example index a797f8e..180011f 100644 --- a/src/pacroller/config.json.example +++ b/src/pacroller/config.json.example @@ -16,5 +16,6 @@ ], "need_restart": false, "need_restart_cmd": ["needrestart", "-r", "a", "-m", "a", "-l"], - "systemd-check": true + "systemd-check": true, + "clear_pkg_cache": false } diff --git a/src/pacroller/config.py b/src/pacroller/config.py index 9a02c16..363c27d 100644 --- a/src/pacroller/config.py +++ b/src/pacroller/config.py @@ -7,6 +7,7 @@ LIB_DIR = Path('/var/lib/pacroller') DB_FILE = 'db' PACMAN_CONFIG = '/etc/pacman.conf' PACMAN_LOG = '/var/log/pacman.log' +PACMAN_PKG_DIR = '/var/cache/pacman/pkg' assert LIB_DIR.is_dir() if (cfg := (CONFIG_DIR / CONFIG_FILE)).exists(): @@ -41,3 +42,4 @@ for i in NEEDRESTART_CMD: assert isinstance(i, str) SYSTEMD = bool(_config.get('systemd-check', True)) +PACMAN_SCC = bool(_config.get('clear_pkg_cache', False)) diff --git a/src/pacroller/main.py b/src/pacroller/main.py index 01b0d58..b3e613e 100644 --- a/src/pacroller/main.py +++ b/src/pacroller/main.py @@ -14,7 +14,8 @@ from pacroller.utils import execute_with_io, UnknownQuestionError, back_readline from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net, checkReport from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, PACMAN_LOG, PACMAN_CONFIG, TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, SYNC_SH, - EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD) + EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD, + PACMAN_PKG_DIR, PACMAN_SCC) logger = logging.getLogger() @@ -203,6 +204,11 @@ def main() -> None: else: logger.debug('using fallback locale C') environ['LANG'] = 'C' + def clear_pkg_cache() -> None: + logger.debug('clearing package cache') + for i in Path(PACMAN_PKG_DIR).iterdir(): + if i.is_file(): + i.unlink() def run_needrestart(ignore_error=False) -> None: logger.debug('running needrestart') try: @@ -260,6 +266,8 @@ def main() -> None: exit(2) if NEEDRESTART: run_needrestart() + if PACMAN_SCC: + clear_pkg_cache() elif args.action == 'status': count = 0 @@ -307,6 +315,8 @@ def main() -> None: logger.info(f'reset previous error {prev_err}') if NEEDRESTART: run_needrestart(True) + if PACMAN_SCC: + clear_pkg_cache() else: logger.warning('nothing to do')