File 0031-Only-use-LONGSIZE-in-rpm.info-if-available.-Otherwis.patch of Package salt.3514

From d3d7d20b569ad1ae5bc8a7ba1ac6652aa2e47ec5 Mon Sep 17 00:00:00 2001
From: rallytime <nicole@saltstack.com>
Date: Tue, 23 Feb 2016 17:20:47 -0700
Subject: [PATCH 31/33] Only use LONGSIZE in rpm.info if available. Otherwise,
 use SIZE.

Fixes #31366
---
 salt/modules/rpm.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/salt/modules/rpm.py b/salt/modules/rpm.py
index 51c72c9..cdf91a6 100644
--- a/salt/modules/rpm.py
+++ b/salt/modules/rpm.py
@@ -422,6 +422,14 @@ def info(*packages, **attr):
         salt '*' lowpkg.info apache2 bash attr=version
         salt '*' lowpkg.info apache2 bash attr=version,build_date_iso,size
     '''
+    # LONGSIZE is not a valid tag for all versions of rpm. If LONGSIZE isn't
+    # available, then we can just use SIZE for older versions. See Issue #31366.
+    rpm_tags = __salt__['cmd.run_all']('rpm --querytags')
+    rpm_tags = rpm_tags.get('stdout').split('\n')
+    if 'LONGSIZE' in rpm_tags:
+        size_tag = '%{LONGSIZE}'
+    else:
+        size_tag = '%{SIZE}'
 
     cmd = packages and "rpm -q {0}".format(' '.join(packages)) or "rpm -qa"
 
@@ -440,7 +448,7 @@ def info(*packages, **attr):
         "build_host": "build_host: %{BUILDHOST}\\n",
         "group": "group: %{GROUP}\\n",
         "source_rpm": "source_rpm: %{SOURCERPM}\\n",
-        "size": "size: %{LONGSIZE}\\n",
+        "size": "size: " + size_tag + "\\n",
         "arch": "arch: %{ARCH}\\n",
         "license": "%|LICENSE?{license: %{LICENSE}\\n}|",
         "signature": "signature: %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:"
-- 
2.1.4

openSUSE Build Service is sponsored by