Skip to content

Commit 28c3bc8

Browse files
authored
Merge pull request #2819 from OSInside/cleanup_build_metadata
Cleanup build metadata
2 parents 8751268 + 14c5143 commit 28c3bc8

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

kiwi/builder/disk.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,10 @@ def _build_main_system(
926926
]
927927
)
928928

929+
# cleanup build metadata
930+
if os.access(f'{root}/', os.W_OK):
931+
disk_system.cleanup()
932+
929933
# set root filesystem properties
930934
if system:
931935
self._setup_property_root_is_readonly_snapshot(system)

kiwi/system/setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,20 @@ def cleanup(self) -> None:
168168
Command.run(
169169
[
170170
'chroot', self.root_dir,
171-
'rm', '-rf', '.kconfig', defaults.IMAGE_METADATA_DIR
171+
'rm', '-f',
172+
'.kconfig',
173+
'.profile',
174+
'config.bootoptions',
175+
'config.partids'
172176
]
173177
)
178+
meta_dir = f'{self.root_dir}/{defaults.IMAGE_METADATA_DIR}'
179+
if os.path.isdir(meta_dir):
180+
image_meta = MountManager(
181+
device='none', mountpoint=meta_dir
182+
)
183+
image_meta.umount()
184+
Path.wipe(meta_dir)
174185

175186
def import_repositories_marked_as_imageinclude(self) -> None:
176187
"""

test/unit/builder/disk_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ def test_create_disk_standard_root_with_dracut_initrd(
870870
]
871871
disk_system.call_pre_disk_script.assert_called_once_with()
872872
disk_system.call_disk_script.assert_called_once_with()
873+
disk_system.cleanup.assert_called_once_with()
873874
self.setup.call_edit_boot_config_script.assert_called_once_with(
874875
'btrfs', 1
875876
)

test/unit/system/setup_test.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,24 @@ def side_effect(arg):
373373
@patch('kiwi.command.Command.run')
374374
def test_cleanup(self, mock_command):
375375
self.setup.cleanup()
376-
mock_command.assert_called_once_with(
377-
['chroot', 'root_dir', 'rm', '-rf', '.kconfig', 'image']
378-
)
376+
assert mock_command.call_args_list == [
377+
call(
378+
[
379+
'chroot', 'root_dir', 'rm', '-f',
380+
'.kconfig',
381+
'.profile',
382+
'config.bootoptions',
383+
'config.partids'
384+
]
385+
),
386+
call(
387+
command=['mountpoint', '-q', 'root_dir/image'],
388+
raise_on_error=False
389+
),
390+
call(
391+
['rm', '-r', '-f', 'root_dir/image']
392+
)
393+
]
379394

380395
@patch('kiwi.system.setup.ArchiveTar')
381396
@patch('kiwi.system.setup.glob.iglob')

0 commit comments

Comments
 (0)