rpm/0018-Make-sure-to-reset-file-attributes-for-generated-bui.patch
Igor Gnatenko 3992a6874b Fix brokeness when using %filter_setup (RHBZ #1468476)
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-07-07 11:39:52 +02:00

195 lines
6.3 KiB
Diff

From 651264c51dfb13bf78bb969a429719f301497631 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Wed, 15 Mar 2017 20:07:29 +0100
Subject: [PATCH 18/54] Make sure to reset file attributes for generated
build-id directories.
[Note this patch is currently being tested in Fedora. See bug below.]
When creating the build-id directories we should reset the file attributes
to the defaults. Otherwise if the file list contained an %attr or %defattr
the directories would come out with the wrong mode.
Includes a testcase based on a spec by Igor Gnatenko that fails before
and Check that build-id directories are created with the right permissions
even if the spec file sets attrs explicitly.
https://bugzilla.redhat.com/show_bug.cgi?id=1432372
Signed-off-by: Mark Wielaard <mark@klomp.org>
(cherry picked from commit b91dc6106e360f13ff365dfac247191942039152)
---
build/files.c | 21 +++++++++++++++++++
tests/Makefile.am | 2 ++
tests/data/SOURCES/hello.c | 8 +++++++
tests/data/SPECS/hello-attr-buildid.spec | 27 ++++++++++++++++++++++++
tests/rpmbuildid.at | 36 ++++++++++++++++++++++++++++++++
5 files changed, 94 insertions(+)
create mode 100644 tests/data/SOURCES/hello.c
create mode 100644 tests/data/SPECS/hello-attr-buildid.spec
diff --git a/build/files.c b/build/files.c
index fef0c6960..728a44ba2 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1770,6 +1770,7 @@ static int generateBuildIDs(FileList fl)
char *mainiddir = NULL;
char *debugiddir = NULL;
if (rc == 0) {
+ char *attrstr;
/* Add .build-id directories to hold the subdirs/symlinks. */
#define BUILD_ID_DIR "/usr/lib/.build-id"
#define DEBUG_ID_DIR "/usr/lib/debug/.build-id"
@@ -1777,6 +1778,18 @@ static int generateBuildIDs(FileList fl)
mainiddir = rpmGetPath(fl->buildRoot, BUILD_ID_DIR, NULL);
debugiddir = rpmGetPath(fl->buildRoot, DEBUG_ID_DIR, NULL);
+ /* Make sure to reset all file flags to defaults.
+ Uses parseForAttr to reset ar, arFlags, and specdFlags.
+ Note that parseForAttr pokes at the attrstr, so we cannot
+ just pass a static string. */
+ fl->def.verifyFlags = RPMVERIFY_ALL;
+ fl->cur.verifyFlags = RPMVERIFY_ALL;
+ fl->def.specdFlags |= SPECD_VERIFY;
+ fl->cur.specdFlags |= SPECD_VERIFY;
+ attrstr = xstrdup ("%defattr(-,root,root)");
+ parseForAttr(fl->pool, attrstr, 1, &fl->def);
+ free (attrstr);
+
/* Supported, but questionable. */
if (needMain && needDbg)
rpmlog(RPMLOG_WARNING,
@@ -1786,8 +1799,12 @@ static int generateBuildIDs(FileList fl)
if ((rc = rpmioMkpath(mainiddir, 0755, -1, -1)) != 0) {
rpmlog(RPMLOG_ERR, "%s %s: %m\n", errdir, mainiddir);
} else {
+ rasprintf (&attrstr, "%s %s", "%attr(-,root,root) ",
+ mainiddir);
+ parseForAttr(fl->pool, attrstr, 0, &fl->cur);
fl->cur.isDir = 1;
rc = addFile(fl, mainiddir, NULL);
+ free (attrstr);
}
}
@@ -1795,8 +1812,12 @@ static int generateBuildIDs(FileList fl)
if ((rc = rpmioMkpath(debugiddir, 0755, -1, -1)) != 0) {
rpmlog(RPMLOG_ERR, "%s %s: %m\n", errdir, debugiddir);
} else {
+ rasprintf (&attrstr, "%s %s", "%attr(-,root,root) ",
+ debugiddir);
+ parseForAttr(fl->pool, attrstr, 0, &fl->cur);
fl->cur.isDir = 1;
rc = addFile(fl, debugiddir, NULL);
+ free (attrstr);
}
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 10555ce9a..d9586da1d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -68,6 +68,8 @@ EXTRA_DIST += data/RPMS/hello-2.0-1.i686.rpm
EXTRA_DIST += data/RPMS/hello-2.0-1.x86_64.rpm
EXTRA_DIST += data/SRPMS/foo-1.0-1.src.rpm
EXTRA_DIST += data/SRPMS/hello-1.0-1.src.rpm
+EXTRA_DIST += data/SOURCES/hello.c
+EXTRA_DIST += data/SPECS/hello-attr-buildid.spec
# testsuite voodoo
AUTOTEST = $(AUTOM4TE) --language=autotest
diff --git a/tests/data/SOURCES/hello.c b/tests/data/SOURCES/hello.c
new file mode 100644
index 000000000..020484eed
--- /dev/null
+++ b/tests/data/SOURCES/hello.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+main (void)
+{
+ printf ("Hello, world!\n");
+ return 0;
+}
diff --git a/tests/data/SPECS/hello-attr-buildid.spec b/tests/data/SPECS/hello-attr-buildid.spec
new file mode 100644
index 000000000..cdab95fff
--- /dev/null
+++ b/tests/data/SPECS/hello-attr-buildid.spec
@@ -0,0 +1,27 @@
+Name: test
+Version: 1.0
+Release: 1
+Summary: Test
+
+License: Public Domain
+URL: https://fedoraproject.org
+Source: hello.c
+
+%description
+%{summary}.
+
+%prep
+%autosetup -c -D -T
+cp -a %{S:0} .
+
+%build
+gcc -g hello.c -o hello
+
+%install
+mkdir -p %{buildroot}%{_bindir}
+install -D -p -m 0755 -t %{buildroot}%{_bindir} hello
+
+%files
+%attr(644,root,root) %{_bindir}/hello
+
+%changelog
diff --git a/tests/rpmbuildid.at b/tests/rpmbuildid.at
index 15c06202f..1cae26dbf 100644
--- a/tests/rpmbuildid.at
+++ b/tests/rpmbuildid.at
@@ -1166,3 +1166,39 @@ if test "$id1" == "$id2"; then echo "equal"; else echo "unequal $id1 $id2"; fi
],
[ignore])
AT_CLEANUP
+
+# ------------------------------
+# Check that build-id directories are created with the right permissions
+# even if the spec file sets attrs explicitly.
+AT_SETUP([rpmbuild buildid attrs])
+AT_KEYWORDS([build] [debuginfo] [buildid])
+AT_CHECK([
+rm -rf ${TOPDIR}
+AS_MKDIR_P(${TOPDIR}/SOURCES)
+
+# Setup sources
+cp "${abs_srcdir}"/data/SOURCES/hello.c ${TOPDIR}/SOURCES
+
+# Build, contains one ELF which should have a buildid.
+run rpmbuild \
+ --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
+ --rcfile=${abs_top_builddir}/rpmrc \
+ --define="_build_id_links compat" \
+ --define "_unique_debug_names 1" \
+ --define "_unique_debug_srcs 1" \
+ --quiet -ba "${abs_srcdir}"/data/SPECS/hello-attr-buildid.spec
+
+run rpm -qp --qf "[[%{filenames} %{filemodes:perms}\n]]" \
+ ${abs_builddir}/testing/build/RPMS/*/test-1.0-1*rpm \
+ | grep "build-id d"
+
+run rpm -qp --qf "[[%{filenames} %{filemodes:perms}\n]]" \
+ ${abs_builddir}/testing/build/RPMS/*/test-debuginfo-1.0-1*rpm \
+ | grep "build-id d"
+],
+[0],
+[/usr/lib/.build-id drwxr-xr-x
+/usr/lib/debug/.build-id drwxr-xr-x
+],
+[ignore])
+AT_CLEANUP
--
2.13.2