From ac84a3c10e73ec7e4cfd4220b345f534149325d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Wed, 12 Feb 2020 15:14:14 -0300 Subject: [PATCH] [aur] root check refactoring --- CHANGELOG.md | 2 +- bauh/gems/arch/controller.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3ec8fc..93768683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - checking architecture dependencies (x86_64, i686) - architecture dependencies are displayed on the info window as well - optimizations to speed up zst packages building - - showing a warning messaging when trying to install / update a package with the root user + - showing a warning messaging when trying to install / update / downgrade a package with the root user - UI: - **Settings** available as a tray action as well - minor improvements diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index de3abb1d..ccd98afc 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -192,6 +192,9 @@ class ArchManager(SoftwareManager): return SearchResult(apps, None, len(apps)) def downgrade(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher) -> bool: + if not self._check_action_allowed(pkg, watcher): + return False + self.local_config = read_config() handler = ProcessHandler(watcher) @@ -262,14 +265,20 @@ class ArchManager(SoftwareManager): if os.path.exists(pkg.get_disk_cache_path()): shutil.rmtree(pkg.get_disk_cache_path()) - def update(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher) -> bool: + def _check_action_allowed(self, pkg: ArchPackage, watcher: ProcessWatcher) -> bool: if user.is_root() and pkg.mirror == 'aur': watcher.show_message(title=self.i18n['arch.install.aur.root_error.title'], body=self.i18n['arch.install.aur.root_error.body'], type_=MessageType.ERROR) return False + return True + + def update(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher) -> bool: + if not self._check_action_allowed(pkg, watcher): + return False self.local_config = read_config() + try: return self.install(pkg=pkg, root_password=root_password, watcher=watcher, skip_optdeps=True) finally: @@ -900,10 +909,7 @@ class ArchManager(SoftwareManager): ArchCompilationOptimizer(self.context.logger).optimize() def install(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher, skip_optdeps: bool = False) -> bool: - if user.is_root() and pkg.mirror == 'aur': - watcher.show_message(title=self.i18n['arch.install.aur.root_error.title'], - body=self.i18n['arch.install.aur.root_error.body'], - type_=MessageType.ERROR) + if not self._check_action_allowed(pkg, watcher): return False clean_config = False