diff --git a/rpmlint/pkg.py b/rpmlint/pkg.py index ae44c77f5..08e271be2 100644 --- a/rpmlint/pkg.py +++ b/rpmlint/pkg.py @@ -621,7 +621,7 @@ def _extract_rpm(self, dirname, verbose): subprocess.check_output('rpm2archive - | tar -xz && chmod -R +rX .', shell=True, env=ENGLISH_ENVIRONMENT, stderr=stderr, stdin=rpm_data) else: - command_str = f'rpm2cpio {quote(str(filename))} | cpio -id ; chmod -R +rX .' + command_str = f'rpm2cpio {quote(str(filename))} | cpio -id && chmod -R +rX .' subprocess.check_output(command_str, shell=True, env=ENGLISH_ENVIRONMENT, stderr=stderr) self.extracted = True return dirname diff --git a/test/test_lint.py b/test/test_lint.py index 202245cd0..d039acd5e 100644 --- a/test/test_lint.py +++ b/test/test_lint.py @@ -338,6 +338,9 @@ def test_header_information(capsys): @pytest.mark.parametrize('configs', [list(Path('configs').glob('*/*.toml'))]) @pytest.mark.no_cover def test_run_full_rpm(capsys, packages, configs): + # the package cannot be extracted using rpm2cpio because it contains a directory without 'x' permission + packages.remove(Path('test/binary/python311-pytest-xprocess-0.23.0-2.4.noarch.rpm')) + number_of_pkgs = len(packages) additional_options = { 'rpmfile': packages, diff --git a/test/test_pkg.py b/test/test_pkg.py index 805eb42b6..415c80b39 100644 --- a/test/test_pkg.py +++ b/test/test_pkg.py @@ -1,3 +1,7 @@ +import os +import subprocess +import unittest.mock as mock + import pytest import rpm from rpmlint.pkg import parse_deps, rangeCompare @@ -25,5 +29,21 @@ def test_range_compare(): @pytest.mark.parametrize('package', ['binary/python311-pytest-xprocess']) -def test_extract(package, tmp_path): - get_tested_package(package, tmp_path) +def test_extract_fail(package, tmp_path): + """ + Check that rpm2cpio fails to extract this package because it has no + permissions to some files. + """ + + # Root can extract the package, so nothing to check + if os.getuid() == 0: + return + + with mock.patch('shutil.which') as mock_which: + mock_which.return_value = None + # the package cannot be extracted using rpm2cpio because it contains a directory without 'x' permission + with pytest.raises(subprocess.CalledProcessError) as exc: + get_tested_package(package, tmp_path) + mock_which.assert_called_once_with('rpm2archive') + # check that it was rpm2cpio what failed + assert exc.match(r'rpm2cpio .*')