From 7eb620f595486309670797a2436559598ff1f8f0 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 30 Aug 2017 15:28:23 +0300 Subject: [PATCH] Restore 4.13 behavior with single value tags in query format arrays Rpm documentation actually states that you must use %{=TAG} for the case commit 7f47cbbd7d1600ae280e48a655c9e870cf9361e0 was trying to fix, but caused regressions in other situations. So the 4.12 behavior is little more than accidental, rpm is actually supposed to error out here (but doesn't, which is another bug). This reverts commits 7f47cbbd7d1600ae280e48a655c9e870cf9361e0 and ead9cdd587bbf052722f0f8598e0983e565e3415. --- lib/headerfmt.c | 38 +++++++------------------------------- tests/rpmquery.at | 1 - 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/lib/headerfmt.c b/lib/headerfmt.c index fdd842c60..3f1880e5f 100644 --- a/lib/headerfmt.c +++ b/lib/headerfmt.c @@ -414,13 +414,6 @@ static int parseFormat(headerSprintfArgs hsa, char * str, goto errxit; } - /* Set justOne = 1 for non ARRAY tags */ - if (token->type == PTOK_TAG && - !(rpmTagGetReturnType(token->u.tag.tag) & - RPM_ARRAY_RETURN_TYPE)) { - token->u.tag.justOne = 1; - } - start = next; break; @@ -689,8 +682,8 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token, int element) { char * t, * te; - int i, j, found, singleItem; - int count, numElements; + int i, j, found; + rpm_count_t count, numElements; sprintfToken spft; int condNumFormats; size_t need; @@ -739,32 +732,23 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token, break; case PTOK_ARRAY: - numElements = -1; - singleItem = 0; + numElements = 0; found = 0; spft = token->u.array.format; - /* get number of array items */ for (i = 0; i < token->u.array.numTokens; i++, spft++) { rpmtd td = NULL; - if (spft->type != PTOK_TAG) continue; + if (spft->type != PTOK_TAG || + spft->u.tag.justOne) continue; if (!(td = getData(hsa, spft->u.tag.tag))) { continue; } - count = rpmtdCount(td); found = 1; + count = rpmtdCount(td); - if (spft->u.tag.justOne) { - if (count) { - singleItem = 1; - } - continue; - } - - - if (numElements > 0 && count != numElements) + if (numElements > 1 && count != numElements) switch (td->type) { default: hsaError(hsa, @@ -779,14 +763,6 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token, numElements = count; } - if (numElements == -1 && singleItem) { - /* only justOne elements */ - numElements = 1; - } else if (numElements == -1) { - /* nothing at all */ - numElements = 0; - } - if (found) { int isxml; diff --git a/tests/rpmquery.at b/tests/rpmquery.at index 334436bea..1ccce9663 100644 --- a/tests/rpmquery.at +++ b/tests/rpmquery.at @@ -416,7 +416,6 @@ AT_CLEANUP AT_SETUP([xml format]) AT_KEYWORDS([query]) AT_CHECK([ -AT_XFAIL_IF([test $RPM_XFAIL -ne 0]) runroot rpm -qp --xml data/RPMS/hello-2.0-1.x86_64.rpm ], [0],