From bcc9c70322a04365a92be7093e2f2c3d0b78c238 Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 16 Jul 2023 09:38:40 -0700 Subject: [PATCH] Fix async yield with some try/finally --- melamine/filesystems/ext23.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/melamine/filesystems/ext23.py b/melamine/filesystems/ext23.py index bb82d2d..e895583 100644 --- a/melamine/filesystems/ext23.py +++ b/melamine/filesystems/ext23.py @@ -59,20 +59,16 @@ class EXT23Handler: inode = path.stat().st_ino fs = ext2_filsys() - ret = self.libext2fs.ext2fs_open(path.encode(), 0, 0, 0, ctypes.byref(fs)) - if ret != 0: - return [] - - scan = ext2_inode_scan() - ret = self.libext2fs.ext2fs_open_inode_scan(fs, ctypes.byref(scan)) - if ret != 0: - self.libext2fs.ext2fs_close(fs) - return [] - - inode_large = ext2_inode_large() - while self.libext2fs.ext2fs_get_next_inode(scan, ctypes.byref(inode_large)) == 0: - if inode_large.i_links_count > 1 and inode_large.i_file_acl == inode: - yield Path(fs.fs_mount_point) / scan.name.decode() - - self.libext2fs.ext2fs_close_inode_scan(scan) - self.libext2fs.ext2fs_close(fs) + if self.libext2fs.ext2fs_open(path.encode(), 0, 0, 0, ctypes.byref(fs)) == 0: + try: + scan = ext2_inode_scan() + try: + if self.libext2fs.ext2fs_open_inode_scan(fs, ctypes.byref(scan)) == 0: + inode_large = ext2_inode_large() + while self.libext2fs.ext2fs_get_next_inode(scan, ctypes.byref(inode_large)) == 0: + if inode_large.i_links_count > 1 and inode_large.i_file_acl == inode: + yield Path(fs.fs_mount_point) / scan.name.decode() + finally: + self.libext2fs.ext2fs_close_inode_scan(scan) + finally: + self.libext2fs.ext2fs_close(fs)