From 9482815b711558ce7b11271a63cba31cf7d71c4e Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 17 Nov 2013 14:18:34 +0100 Subject: [PATCH 1/2] Fix behavior of urpmi module where it always return "changed" even when a package is already installed, since urpmi will always return 0 wether it install or not. --- library/packaging/urpmi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/packaging/urpmi b/library/packaging/urpmi index 4ff01a7413..ac96a9d74f 100644 --- a/library/packaging/urpmi +++ b/library/packaging/urpmi @@ -90,6 +90,13 @@ def query_package(module, name): else: return False +def query_package_provides(module, name): + + # rpm -q returns 0 if the package is installed, + # 1 if it is not installed + rc = os.system("rpm -q --provides %s >/dev/null" % (name)) + return rc == 0 + def update_package_db(module): rc = os.system("urpmi.update -a -q") @@ -125,7 +132,8 @@ def install_packages(module, pkgspec, force=True, no_suggests=True): packages = "" for package in pkgspec: - packages += "'%s' " % package + if not query_package_provides(module, package): + packages += "'%s' " % package if len(packages) != 0: if no_suggests: From 0d8b81cd95a2f847f083fe03d769e7206415542f Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 17 Nov 2013 15:10:17 +0100 Subject: [PATCH 2/2] optionally use rpm python module instead of calling a external executable, to avoid the cost of forking. Since python-rpm is not automatically present, we still fallback on the slower rpm fork method. --- library/packaging/urpmi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/packaging/urpmi b/library/packaging/urpmi index ac96a9d74f..46745fce5d 100644 --- a/library/packaging/urpmi +++ b/library/packaging/urpmi @@ -76,11 +76,18 @@ import json import shlex import os import sys +try: + import rpm + USE_PYTHON = True +except ImportError: + USE_PYTHON = False URPMI_PATH = '/usr/sbin/urpmi' URPME_PATH = '/usr/sbin/urpme' def query_package(module, name): + if USE_PYTHON: + return rpm.TransactionSet().dbMatch(rpm.RPMTAG_NAME, name).count() != 0 # rpm -q returns 0 if the package is installed, # 1 if it is not installed @@ -91,6 +98,8 @@ def query_package(module, name): return False def query_package_provides(module, name): + if USE_PYTHON: + return rpm.TransactionSet().dbMatch(rpm.RPMTAG_PROVIDES, name).count() != 0 # rpm -q returns 0 if the package is installed, # 1 if it is not installed