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.
This commit is contained in:
Panu Matilainen 2022-04-01 12:14:13 +03:00
parent 125201cc52
commit 10804d32d9
2 changed files with 25 additions and 59 deletions

View File

@ -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;
if (*argv[1]) {
expandMacro(mb, "%__rpmuncompress ", 0);
mbAppendStr(mb, argv[1]);
}
mbAppendStr(mb, buf);
exit:
free(buf);
}
static void doExpand(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)

View File

@ -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