summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2022-04-01 12:14:13 +0300
committerPanu Matilainen <pmatilai@redhat.com>2022-04-04 10:04:25 +0300
commit10804d32d9e092b4898ec65938e7b157deb844fa (patch)
treee7426707e477529ea4989247ec937aacb5046d5a
parent125201cc525d37ee98bc3e181cc95a2075664acd (diff)
downloadrpm-10804d32d9e092b4898ec65938e7b157deb844fa.tar.gz
Use rpmuncompress to handle %{uncompress:...}
This means that finally there's just one place that when adding support for new compress formats, there's in theory there's just one place to update. Reality is a little more complicated, but hey... Adjust tests a bit, and rather test functionality than command output because those reflect command paths which we can't easily adjust now.
-rw-r--r--rpmio/macro.c58
-rw-r--r--tests/rpmmacro.at28
2 files changed, 26 insertions, 60 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index 8a604d483..6b0201a4c 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -1107,60 +1107,10 @@ static void doSP(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)
static void doUncompress(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)
{
- rpmCompressedMagic compressed = COMPRESSED_OTHER;
- char *b, *be, *buf = NULL;
- int c;
-
- if (!*argv[1])
- goto exit;
- buf = xstrdup(argv[1]);
- for (b = buf; (c = *b) && isblank(c);)
- b++;
- for (be = b; (c = *be) && !isblank(c);)
- be++;
- *be = '\0';
-
- if (*b == '\0')
- goto exit;
-
- if (rpmFileIsCompressed(b, &compressed))
- mb->error = 1;
-
- switch (compressed) {
- default:
- case COMPRESSED_NOT:
- expandMacro(mb, "%__cat ", 0);
- break;
- case COMPRESSED_OTHER:
- expandMacro(mb, "%__gzip -dc ", 0);
- break;
- case COMPRESSED_BZIP2:
- expandMacro(mb, "%__bzip2 -dc ", 0);
- break;
- case COMPRESSED_ZIP:
- expandMacro(mb, "%__unzip ", 0);
- break;
- case COMPRESSED_LZMA:
- case COMPRESSED_XZ:
- expandMacro(mb, "%__xz -dc ", 0);
- break;
- case COMPRESSED_LZIP:
- expandMacro(mb, "%__lzip -dc ", 0);
- break;
- case COMPRESSED_LRZIP:
- expandMacro(mb, "%__lrzip -dqo- ", 0);
- break;
- case COMPRESSED_7ZIP:
- expandMacro(mb, "%__7zip x ", 0);
- break;
- case COMPRESSED_ZSTD:
- expandMacro(mb, "%__zstd -dc ", 0);
- break;
- }
- mbAppendStr(mb, buf);
-
-exit:
- free(buf);
+ if (*argv[1]) {
+ expandMacro(mb, "%__rpmuncompress ", 0);
+ mbAppendStr(mb, argv[1]);
+ }
}
static void doExpand(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)
diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at
index 3752c9429..d1490b4d9 100644
--- a/tests/rpmmacro.at
+++ b/tests/rpmmacro.at
@@ -216,24 +216,40 @@ AT_SETUP([uncompress macro 1])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm \
- --define "__gzip /my/bin/gzip" \
+ --define "__rpmuncompress /my/bin/rpmuncompress" \
--eval "%{uncompress:/data/SOURCES/hello-2.0.tar.gz}"
],
[0],
-[/my/bin/gzip -dc /data/SOURCES/hello-2.0.tar.gz
+[/my/bin/rpmuncompress /data/SOURCES/hello-2.0.tar.gz
])
AT_CLEANUP
-AT_SETUP([uncompress macro 2])
+AT_SETUP([uncompress 1])
+AT_KEYWORDS([macros])
+AT_CHECK([
+RPMDB_INIT
+runroot_other ${RPM_CONFIGDIR}/rpmuncompress /data/SOURCES/hello-2.0.tar.gz | tar t
+],
+[0],
+[hello-2.0/
+hello-2.0/COPYING
+hello-2.0/hello.spec
+hello-2.0/hello.c
+hello-2.0/Makefile
+hello-2.0/README
+hello-2.0/FAQ
+])
+AT_CLEANUP
+
+AT_SETUP([uncompress 2])
AT_KEYWORDS([macros])
AT_CHECK([
RPMDB_INIT
echo xxxxxxxxxxxxxxxxxxxxxxxxx > ${RPMTEST}/tmp/"some%%ath"
-runroot rpm \
- --eval "%{uncompress:/tmp/some%%%%ath}"
+runroot_other ${RPM_CONFIGDIR}/rpmuncompress "/tmp/some%%ath"
],
[0],
-[/usr/bin/cat /tmp/some%%ath
+[xxxxxxxxxxxxxxxxxxxxxxxxx
])
AT_CLEANUP