From 70fa14e7fa5deedf30a43bc7192fa44fdee4e073 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 2 Aug 2025 23:34:02 +1200 Subject: [PATCH] test: Drop double removal of the FS image on failure We already have a cleanup function which removes the filesystem, so drop the unnecessary try...except for this. It results in an error on the error path, as we try to remove the filesystem twice. Signed-off-by: Simon Glass --- test/py/tests/fs_helper.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index c9df7a028a9..baf61cbd232 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -116,25 +116,21 @@ class FsHelper: fsi.truncate(self.size_mb << 20) self._do_cleanup = True - try: - mkfs_opt, fs_lnxtype = self._get_fs_args() - check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True, - stdout=DEVNULL if self.quiet else None) + mkfs_opt, fs_lnxtype = self._get_fs_args() + check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True, + stdout=DEVNULL if self.quiet else None) - if self.fs_type.startswith('ext'): - sb_content = check_output(f'tune2fs -l {fs_img}', - shell=True).decode() - if 'metadata_csum' in sb_content: - check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) - elif fs_lnxtype == 'exfat': - check_call(f'fattools cp {self.srcdir}/* {fs_img}', shell=True) - elif self.srcdir and os.listdir(self.srcdir): - flags = f"-smpQ{'' if self.quiet else 'v'}" - check_call(f'mcopy -i {fs_img} {flags} {self.srcdir}/* ::/', - shell=True) - except CalledProcessError: - os.remove(fs_img) - raise + if self.fs_type.startswith('ext'): + sb_content = check_output(f'tune2fs -l {fs_img}', + shell=True).decode() + if 'metadata_csum' in sb_content: + check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) + elif fs_lnxtype == 'exfat': + check_call(f'fattools cp {self.srcdir}/* {fs_img}', shell=True) + elif self.srcdir and os.listdir(self.srcdir): + flags = f"-smpQ{'' if self.quiet else 'v'}" + check_call(f'mcopy -i {fs_img} {flags} {self.srcdir}/* ::/', + shell=True) def setup(self): """Set up the srcdir ready to receive files"""