From 8221668e34aafa1a072d71a224fc11c1058c09e0 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Thu, 3 May 2018 21:25:28 -0400 Subject: [PATCH] Properly handle the exception on missing files (bz1574509) On installs where documentation or additional languages are not installed, rpmlint fails while attempting to iterate over the file list. The files are only opened for their 'magic numbers' which is used in a few tests in BinariesCheck and SourceCheck. Fedora container images sets nodocs and '%_install_langs en_US' (which causes locale files not to be installed). Running rpmlint in such a container results in a traceback when rpmlint attempts to check the packages files. Backport patch from upstream to fix the issue. Resolves: https://bugzilla.redhat.com/1574509 Source: https://github.com/rpm-software-management/rpmlint/commit/d59bc2a --- rpmlint-1.10-missing-files-exception.patch | 44 ++++++++++++++++++++++ rpmlint.spec | 8 +++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 rpmlint-1.10-missing-files-exception.patch diff --git a/rpmlint-1.10-missing-files-exception.patch b/rpmlint-1.10-missing-files-exception.patch new file mode 100644 index 0000000..80935c1 --- /dev/null +++ b/rpmlint-1.10-missing-files-exception.patch @@ -0,0 +1,44 @@ +From 3a072351314c3a3ec11650ad8efd2fc6ececf987 Mon Sep 17 00:00:00 2001 +From: Dirk Mueller +Date: Sat, 4 Nov 2017 02:17:52 +0100 +Subject: [PATCH] Properly handle the exception on missing files + +Missing files raises a FileNotFoundError, not OSError. Also +simplify logic. + +(cherry picked from commit d59bc2a1e2698040553c09610cb2befa1ef8d76a) +--- + Pkg.py | 11 +++-------- + 1 file changed, 3 insertions(+), 8 deletions(-) + +diff --git a/Pkg.py b/Pkg.py +index e257243..01d0289 100644 +--- a/Pkg.py ++++ b/Pkg.py +@@ -714,20 +714,15 @@ class Pkg(AbstractPkg): + pkgfile.magic = "symbolic link to `%s'" % pkgfile.linkto + elif not pkgfile.size: + pkgfile.magic = 'empty' +- if not pkgfile.magic and _magic: ++ if (not pkgfile.magic and ++ not pkgfile.is_ghost and _magic): + # file() method evaluates every file twice with python2, + # use descriptor() method instead + try: + fd = os.open(pkgfile.path, os.O_RDONLY) +- except OSError: +- if not pkgfile.is_ghost: +- raise +- else: + pkgfile.magic = b2s(_magic.descriptor(fd)) +- # libmagic up to 5.18 already closes the descriptor +- try: + os.close(fd) +- except OSError: ++ except FileNotFoundError: + pass + if pkgfile.magic is None: + pkgfile.magic = '' +-- +2.17.0 + diff --git a/rpmlint.spec b/rpmlint.spec index 3037a6c..9e0db98 100644 --- a/rpmlint.spec +++ b/rpmlint.spec @@ -16,7 +16,7 @@ Name: rpmlint Version: 1.10 -Release: 11%{?dist} +Release: 12%{?dist} Summary: Tool for checking common errors in RPM packages Group: Development/Tools License: GPLv2 @@ -34,6 +34,8 @@ Patch0: rpmlint-1.10-ignore-debuginfo-useless-provides.patch # https://github.com/rpm-software-management/rpmlint/commit/c1945e37e2989364c5caedc05aa429a5c2d39f4d # https://github.com/rpm-software-management/rpmlint/commit/f267bf1c60d067436b360c68d8e956876758b268 Patch1: rpmlint-1.10-flake-cleanups.patch +# https://github.com/rpm-software-management/rpmlint/commit/d59bc2a +Patch2: rpmlint-1.10-missing-files-exception.patch BuildArch: noarch %if %{with python3} BuildRequires: python3-devel @@ -86,6 +88,7 @@ and source packages as well as spec files can be checked. %setup -q -n %{name}-%{name}-%{version} %patch0 -p1 -b .debuginfo-useless-provides %patch1 -p1 -b .flake +%patch2 -p1 -b .missing-files sed -i -e /MenuCheck/d Config.py cp -p config config.example install -pm 644 %{SOURCE3} config @@ -135,6 +138,9 @@ make check PYTHON=%{python} PYTEST=%{pytest} FLAKE8=%{flake8} %{_mandir}/man1/rpmlint.1* %changelog +* Thu May 03 2018 Todd Zullinger +- Properly handle the exception on missing files (bz1574509) + * Wed Apr 18 2018 Todd Zullinger - Ignore 'no-documentation' in debugsource packages - Ignore /usr/src/debug/ in debugsource packages