From 42a3be984c557cc19538988a7e9805e50005983f Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Mon, 21 Oct 2019 12:55:05 -0300 Subject: [PATCH] [aur] fix -> not respecting 'ignorepkg' settings in pacman.conf --- CHANGELOG.md | 3 +- bauh/gems/arch/pacman.py | 37 +++++++ tests/gems/arch/pacman_test.py | 23 ++++ tests/gems/arch/resources/pacman.conf | 98 +++++++++++++++++ .../gems/arch/resources/pacman_ign_pkgs.conf | 101 ++++++++++++++++++ 5 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 tests/gems/arch/pacman_test.py create mode 100644 tests/gems/arch/resources/pacman.conf create mode 100644 tests/gems/arch/resources/pacman_ign_pkgs.conf diff --git a/CHANGELOG.md b/CHANGELOG.md index 999dbc0d..5f7a7ee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixes - AUR: - update-checking for some scenarios + - not respecting 'ignorepkg' settings in **pacman.conf** ## [0.7.0] 2019-10-18 ### Features @@ -39,7 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### AppImage support - Search, install, uninstall, downgrade, launch and retrieve the applications history - Supported sources: [AppImageHub](https://appimage.github.io) ( **applications with no releases published to GitHub are currently not available** ) -- Adds desktop entries ( menu shortcuts ) for the installed applications ( **~/.local/share/applications **) +- Adds desktop entries ( menu shortcuts ) for the installed applications ( **~/.local/share/applications**) ## [0.6.4] 2019-10-13 ### Fixes diff --git a/bauh/gems/arch/pacman.py b/bauh/gems/arch/pacman.py index 7681e2b2..678355f0 100644 --- a/bauh/gems/arch/pacman.py +++ b/bauh/gems/arch/pacman.py @@ -1,4 +1,5 @@ import re +from threading import Thread from typing import List, Set from bauh.commons.system import run_cmd, new_subprocess, new_root_subprocess, SystemProcess @@ -71,10 +72,18 @@ def check_installed(pkg: str) -> bool: return bool(res) +def _fill_ignored(res: dict): + res['pkgs'] = list_ignored_packages() + + def list_and_map_installed() -> dict: # returns a dict with with package names as keys and versions as values installed = new_subprocess(['pacman', '-Qq']).stdout # retrieving all installed package names allinfo = new_subprocess(['pacman', '-Qi'], stdin=installed).stdout # retrieving all installed packages info + ignored = {} + thread_ignored = Thread(target=_fill_ignored, args=(ignored,)) + thread_ignored.start() + pkgs, current_pkg = {'mirrors': {}, 'not_signed': {}}, {} for out in new_subprocess(['grep', '-E', '(Name|Description|Version|Validated By)'], stdin=allinfo).stdout: # filtering only the Name and Validated By fields: @@ -96,6 +105,18 @@ def list_and_map_installed() -> dict: # returns a dict with with package names current_pkg = {} + if pkgs and pkgs.get('not_signed'): + thread_ignored.join() + + if ignored['pkgs']: + to_del = set() + for pkg in pkgs['not_signed'].keys(): + if pkg in ignored['pkgs']: + to_del.add(pkg) + + for pkg in to_del: + del pkgs['not_signed'][pkg] + return pkgs @@ -179,3 +200,19 @@ def receive_key(key: str, root_password: str) -> SystemProcess: def sign_key(key: str, root_password: str) -> SystemProcess: return SystemProcess(new_root_subprocess(['pacman-key', '--lsign-key', key], root_password=root_password), check_error_output=False) + +def list_ignored_packages(config_path: str = '/etc/pacman.conf') -> Set[str]: + pacman_conf = new_subprocess(['cat', config_path]) + + ignored = set() + grep = new_subprocess(['grep', '-Eo', r'\s*#*\s*ignorepkg\s*=\s*.+'], stdin=pacman_conf.stdout) + for o in grep.stdout: + if o: + line = o.decode().strip() + + if not line.startswith('#'): + ignored.add(line.split('=')[1].strip()) + + pacman_conf.terminate() + grep.terminate() + return ignored diff --git a/tests/gems/arch/pacman_test.py b/tests/gems/arch/pacman_test.py new file mode 100644 index 00000000..ea7e2c25 --- /dev/null +++ b/tests/gems/arch/pacman_test.py @@ -0,0 +1,23 @@ +import os +from unittest import TestCase + +from bauh.gems.arch import pacman + +FILE_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class PacmanTest(TestCase): + + def test_list_ignored_packages(self): + ignored = pacman.list_ignored_packages(FILE_DIR + '/resources/pacman_ign_pkgs.conf') + + self.assertIsNotNone(ignored) + self.assertEqual(2, len(ignored)) + self.assertIn('google-chrome', ignored) + self.assertIn('firefox', ignored) + + def test_list_ignored_packages__no_ignored_packages(self): + ignored = pacman.list_ignored_packages(FILE_DIR + '/resources/pacman.conf') + + self.assertIsNotNone(ignored) + self.assertEqual(0, len(ignored)) diff --git a/tests/gems/arch/resources/pacman.conf b/tests/gems/arch/resources/pacman.conf new file mode 100644 index 00000000..0649ebfc --- /dev/null +++ b/tests/gems/arch/resources/pacman.conf @@ -0,0 +1,98 @@ +# +# /etc/pacman.conf +# +# See the pacman.conf(5) manpage for option and repository directives + +# +# GENERAL OPTIONS +# +[options] +# The following paths are commented out with their default values listed. +# If you wish to use different paths, uncomment and update the paths. +#RootDir = / +#DBPath = /var/lib/pacman/ +CacheDir = /var/cache/pacman/pkg/ +#LogFile = /var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +#HookDir = /etc/pacman.d/hooks/ +HoldPkg = pacman glibc manjaro-system +# If upgrades are available for these packages they will be asked for first +SyncFirst = manjaro-system archlinux-keyring manjaro-keyring +#XferCommand = /usr/bin/curl -C - -f %u > %o +#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +#UseDelta = 0.7 +Architecture = auto + +# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +#IgnorePkg = +#IgnoreGroup = + +#NoUpgrade = +#NoExtract = + +# Misc options +#UseSyslog +#Color +#TotalDownload +# We cannot check disk space from within a chroot environment +CheckSpace +#VerbosePkgLists + +# By default, pacman accepts packages signed by keys that its local keyring +# trusts (see pacman-key and its man page), as well as unsigned packages. +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +#RemoteFileSigLevel = Required + +# NOTE: You must run `pacman-key --init` before first using pacman; the local +# keyring can then be populated with the keys of all official Manjaro Linux +# packagers with `pacman-key --populate archlinux manjaro`. + +# +# REPOSITORIES +# - can be defined here or included from another file +# - pacman will search repositories in the order defined here +# - local/custom mirrors can be added here or in separate files +# - repositories listed first will take precedence when packages +# have identical names, regardless of version number +# - URLs will have $repo replaced by the name of the current repo +# - URLs will have $arch replaced by the name of the architecture +# +# Repository entries are of the format: +# [repo-name] +# Server = ServerName +# Include = IncludePath +# +# The header [repo-name] is crucial - it must be present and +# uncommented to enable the repo. +# + +# The testing repositories are disabled by default. To enable, uncomment the +# repo name header and Include lines. You can add preferred servers immediately +# after the header, and they will be used before the default mirrors. + +[core] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +[extra] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +[community] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +# If you want to run 32 bit applications on your x86_64 system, +# enable the multilib repositories as required here. + +[multilib] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +# An example of a custom package repository. See the pacman manpage for +# tips on creating your own repositories. +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs \ No newline at end of file diff --git a/tests/gems/arch/resources/pacman_ign_pkgs.conf b/tests/gems/arch/resources/pacman_ign_pkgs.conf new file mode 100644 index 00000000..6e502ab0 --- /dev/null +++ b/tests/gems/arch/resources/pacman_ign_pkgs.conf @@ -0,0 +1,101 @@ +# +# /etc/pacman.conf +# +# See the pacman.conf(5) manpage for option and repository directives + +# +# GENERAL OPTIONS +# +[options] +# The following paths are commented out with their default values listed. +# If you wish to use different paths, uncomment and update the paths. +#RootDir = / +#DBPath = /var/lib/pacman/ +CacheDir = /var/cache/pacman/pkg/ +#LogFile = /var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +#HookDir = /etc/pacman.d/hooks/ +HoldPkg = pacman glibc manjaro-system +# If upgrades are available for these packages they will be asked for first +SyncFirst = manjaro-system archlinux-keyring manjaro-keyring +#XferCommand = /usr/bin/curl -C - -f %u > %o +#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +#UseDelta = 0.7 +Architecture = auto + +# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +#IgnorePkg = +#IgnoreGroup = + +#NoUpgrade = +#NoExtract = + +# Misc options +#UseSyslog +#Color +#TotalDownload +# We cannot check disk space from within a chroot environment +CheckSpace +#VerbosePkgLists + +# By default, pacman accepts packages signed by keys that its local keyring +# trusts (see pacman-key and its man page), as well as unsigned packages. +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +#RemoteFileSigLevel = Required + +# NOTE: You must run `pacman-key --init` before first using pacman; the local +# keyring can then be populated with the keys of all official Manjaro Linux +# packagers with `pacman-key --populate archlinux manjaro`. + +# +# REPOSITORIES +# - can be defined here or included from another file +# - pacman will search repositories in the order defined here +# - local/custom mirrors can be added here or in separate files +# - repositories listed first will take precedence when packages +# have identical names, regardless of version number +# - URLs will have $repo replaced by the name of the current repo +# - URLs will have $arch replaced by the name of the architecture +# +# Repository entries are of the format: +# [repo-name] +# Server = ServerName +# Include = IncludePath +# +# The header [repo-name] is crucial - it must be present and +# uncommented to enable the repo. +# + +# The testing repositories are disabled by default. To enable, uncomment the +# repo name header and Include lines. You can add preferred servers immediately +# after the header, and they will be used before the default mirrors. + +[core] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +[extra] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +[community] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +# If you want to run 32 bit applications on your x86_64 system, +# enable the multilib repositories as required here. + +[multilib] +SigLevel = PackageRequired +Include = /etc/pacman.d/mirrorlist + +# An example of a custom package repository. See the pacman manpage for +# tips on creating your own repositories. +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs +ignorepkg=google-chrome +# ignorepkg=abc +ignorepkg = firefox \ No newline at end of file