Skip to content

Commit d8bc2f7

Browse files
authored
Merge pull request #2654 from alyssarosenzweig/bug/exclude-erofs
Fix globbing with exclude with regex
2 parents ddc7ad0 + 504343f commit d8bc2f7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

kiwi/filesystem/erofs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ def create_on_file(
4545

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

5055
if label:
5156
self.custom_args['create_options'].append('-L')

test/unit/filesystem/erofs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_create_on_file_exclude_data(self, mock_command):
3737
mock_command.assert_called_once_with(
3838
[
3939
'mkfs.erofs', '-z', 'zstd,level=21',
40-
'-L', 'label', '--exclude-regex=foo',
40+
'-L', 'label', '--exclude-regex=^foo$',
4141
'myimage', 'root_dir'
4242
]
4343
)

0 commit comments

Comments
 (0)