Skip to content

Commit

Permalink
Merge pull request #1266 from dmach/fix-rpm2cpio
Browse files Browse the repository at this point in the history
Don't mask rpm2cpio failure in Pkg._extract_rpm()
  • Loading branch information
danigm authored Sep 6, 2024
2 parents 226484c + ce08677 commit 30d350c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 22 additions & 2 deletions test/test_pkg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os
import subprocess
import unittest.mock as mock

import pytest
import rpm
from rpmlint.pkg import parse_deps, rangeCompare
Expand Down Expand Up @@ -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 .*')

0 comments on commit 30d350c

Please sign in to comment.