scripts: Honor the -e flag for scripts

This is required for glibc-all-langpacks at least:
https://bugzilla.redhat.com/show_bug.cgi?id=1367585

Otherwise, its usage is...extraordinarily rare. In fact looking at a snapshot of
`rpm-specs-20170518.tar.xz` from Fedora, the only other use is in
`postfix.spec`, and it appears bogus (the value is already expanded at build
time).

But the glibc case is special, as the value of `install_langs` is indeed
potentially dynamic per system.

Closes: #873
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-07-12 20:50:08 -04:00 committed by Atomic Bot
parent 4222407657
commit 1f3ebba982
3 changed files with 30 additions and 5 deletions

View File

@ -28,6 +28,13 @@
#include "rpmostree-scripts.h" #include "rpmostree-scripts.h"
/* This bit is currently private in librpm */
enum rpmscriptFlags_e {
RPMSCRIPT_FLAG_NONE = 0,
RPMSCRIPT_FLAG_EXPAND = (1 << 0), /* macro expansion */
RPMSCRIPT_FLAG_QFORMAT = (1 << 1), /* header queryformat expansion */
};
typedef struct { typedef struct {
const char *desc; const char *desc;
rpmsenseFlags sense; rpmsenseFlags sense;
@ -224,8 +231,12 @@ impl_run_rpm_script (const KnownRpmScriptKind *rpmscript,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autofree char *script_owned = NULL;
const char *script = headerGetString (hdr, rpmscript->tag); const char *script = headerGetString (hdr, rpmscript->tag);
g_assert (script); g_assert (script);
const rpmFlags flags = headerGetNumber (hdr, rpmscript->flagtag);
if (flags & RPMSCRIPT_FLAG_EXPAND)
script = script_owned = rpmExpand (script, NULL);
struct rpmtd_s td; struct rpmtd_s td;
g_autofree char **args = NULL; g_autofree char **args = NULL;

View File

@ -377,7 +377,7 @@ Summary: %{name}
License: GPLv2+ License: GPLv2+
EOF EOF
local build= install= files= pretrans= pre= post= posttrans= post_interp= local build= install= files= pretrans= pre= post= posttrans= post_args=
while [ $# -ne 0 ]; do while [ $# -ne 0 ]; do
local section=$1; shift local section=$1; shift
local arg=$1; shift local arg=$1; shift
@ -388,8 +388,8 @@ EOF
echo "Provides: $arg" >> $spec;; echo "Provides: $arg" >> $spec;;
conflicts) conflicts)
echo "Conflicts: $arg" >> $spec;; echo "Conflicts: $arg" >> $spec;;
post_interp) post_args)
post_interp="$arg"; post="$1"; shift;; post_args="$arg";;
version|release|arch|build|install|files|pretrans|pre|post|posttrans) version|release|arch|build|install|files|pretrans|pre|post|posttrans)
declare $section="$arg";; declare $section="$arg";;
*) *)
@ -417,7 +417,7 @@ $pretrans
${pre:+%pre} ${pre:+%pre}
$pre $pre
${post:+%post} ${post_interp:+-p ${post_interp}} ${post:+%post} ${post_args}
$post $post
${posttrans:+%posttrans} ${posttrans:+%posttrans}

View File

@ -32,7 +32,8 @@ vm_build_rpm scriptpkg1 \
pre "groupadd -r scriptpkg1" \ pre "groupadd -r scriptpkg1" \
pretrans "# http://lists.rpm.org/pipermail/rpm-ecosystem/2016-August/000391.html pretrans "# http://lists.rpm.org/pipermail/rpm-ecosystem/2016-August/000391.html
echo i should've been ignored && exit 1" \ echo i should've been ignored && exit 1" \
post_interp /usr/bin/python 'open("/usr/lib/rpmostreetestinterp", "w")' \ post_args "-p /usr/bin/python" \
post 'open("/usr/lib/rpmostreetestinterp", "w")' \
posttrans "# Firewalld; https://github.com/projectatomic/rpm-ostree/issues/638 posttrans "# Firewalld; https://github.com/projectatomic/rpm-ostree/issues/638
. /etc/os-release || : . /etc/os-release || :
# See https://github.com/projectatomic/rpm-ostree/pull/647 # See https://github.com/projectatomic/rpm-ostree/pull/647
@ -63,6 +64,19 @@ echo "ok group scriptpkg1 active"
vm_has_files "/usr/lib/rpmostreetestinterp" vm_has_files "/usr/lib/rpmostreetestinterp"
echo "ok interp" echo "ok interp"
vm_build_rpm scriptpkg2 \
post_args "-e" \
post 'echo %%{_prefix} > /usr/lib/prefixtest.txt'
vm_build_rpm scriptpkg3 \
post 'echo %%{_prefix} > /usr/lib/noprefixtest.txt'
vm_rpmostree pkg-add scriptpkg{2,3}
vm_rpmostree ex livefs
vm_cmd cat /usr/lib/noprefixtest.txt > noprefixtest.txt
assert_file_has_content noprefixtest.txt '%{_prefix}'
vm_cmd cat /usr/lib/prefixtest.txt > prefixtest.txt
assert_file_has_content prefixtest.txt "/usr"
echo "ok script expansion"
# And now, things that should fail # And now, things that should fail
vm_build_rpm rofiles-violation \ vm_build_rpm rofiles-violation \
post "echo should fail >> /usr/share/licenses/glibc/COPYING" post "echo should fail >> /usr/share/licenses/glibc/COPYING"