Skip to content

Commit

Permalink
Merge pull request #2654 from alyssarosenzweig/bug/exclude-erofs
Browse files Browse the repository at this point in the history
Fix globbing with exclude with regex
  • Loading branch information
schaefi authored Sep 25, 2024
2 parents ddc7ad0 + 504343f commit d8bc2f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion kiwi/filesystem/erofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ def create_on_file(

if exclude:
for item in exclude:
exclude_options.append(f'--exclude-regex={item}')
# item is a glob, but erofs requires a POSIX extended regex.
# Translate the glob to a regex for correct behaviour.
#
# We can't use fnmatch.translate, as that produces a Python regex.
as_regex = '^' + item.replace('*', '.*') + '$'
exclude_options.append(f'--exclude-regex={as_regex}')

if label:
self.custom_args['create_options'].append('-L')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/filesystem/erofs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_create_on_file_exclude_data(self, mock_command):
mock_command.assert_called_once_with(
[
'mkfs.erofs', '-z', 'zstd,level=21',
'-L', 'label', '--exclude-regex=foo',
'-L', 'label', '--exclude-regex=^foo$',
'myimage', 'root_dir'
]
)

0 comments on commit d8bc2f7

Please sign in to comment.