Skip to content

Commit

Permalink
scripts: Honor the -e flag for scripts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Jul 18, 2017
1 parent 4222407 commit 1f3ebba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/libpriv/rpmostree-scripts.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@

#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 {
const char *desc;
rpmsenseFlags sense;
Expand Down Expand Up @@ -224,8 +231,12 @@ impl_run_rpm_script (const KnownRpmScriptKind *rpmscript,
GCancellable *cancellable,
GError **error)
{
g_autofree char *script_owned = NULL;
const char *script = headerGetString (hdr, rpmscript->tag);
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;
g_autofree char **args = NULL;
Expand Down
8 changes: 4 additions & 4 deletions tests/common/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Summary: %{name}
License: GPLv2+
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
local section=$1; shift
local arg=$1; shift
Expand All @@ -388,8 +388,8 @@ EOF
echo "Provides: $arg" >> $spec;;
conflicts)
echo "Conflicts: $arg" >> $spec;;
post_interp)
post_interp="$arg"; post="$1"; shift;;
post_args)
post_args="$arg";;
version|release|arch|build|install|files|pretrans|pre|post|posttrans)
declare $section="$arg";;
*)
Expand Down Expand Up @@ -417,7 +417,7 @@ $pretrans
${pre:+%pre}
$pre
${post:+%post} ${post_interp:+-p ${post_interp}}
${post:+%post} ${post_args}
$post
${posttrans:+%posttrans}
Expand Down
16 changes: 15 additions & 1 deletion tests/vmcheck/test-layering-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ vm_build_rpm scriptpkg1 \
pre "groupadd -r scriptpkg1" \
pretrans "# http://lists.rpm.org/pipermail/rpm-ecosystem/2016-August/000391.html
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
. /etc/os-release || :
# See https://github.com/projectatomic/rpm-ostree/pull/647
Expand Down Expand Up @@ -63,6 +64,19 @@ echo "ok group scriptpkg1 active"
vm_has_files "/usr/lib/rpmostreetestinterp"
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
vm_build_rpm rofiles-violation \
post "echo should fail >> /usr/share/licenses/glibc/COPYING"
Expand Down

0 comments on commit 1f3ebba

Please sign in to comment.