From fd2fb7e419863d4c2952e53c36d1db2cdbcc6834 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 21 Nov 2024 11:40:20 -0300 Subject: [PATCH] BIOSExtractor: Fix PhoenixNet extraction EISDIR errors --- biostools/extractors.py | 87 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/biostools/extractors.py b/biostools/extractors.py index 1a64cf5..de8282c 100644 --- a/biostools/extractors.py +++ b/biostools/extractors.py @@ -496,59 +496,56 @@ class BIOSExtractor(Extractor): for dest_dir_file in dest_dir_files: # Read and check for ROS header. dest_dir_file_path = os.path.join(dest_dir_0, dest_dir_file) - in_f = open(dest_dir_file_path, 'rb') - dest_dir_file_header = in_f.read(3) + if not os.path.isfile(dest_dir_file_path): + continue + with open(dest_dir_file_path, 'rb') as in_f: + if in_f.read(3) == b'ROS': + self.debug_print('Extracting PhoenixNet ROS:', dest_dir_file) - if dest_dir_file_header == b'ROS': - self.debug_print('Extracting PhoenixNet ROS:', dest_dir_file) + # Create new destination directory for the expanded ROS. + dest_dir_ros = os.path.join(dest_dir_0, dest_dir_file + ':') + if util.try_makedirs(dest_dir_ros): + # Skip initial header. + in_f.seek(32) - # Create new destination directory for the expanded ROS. - dest_dir_ros = os.path.join(dest_dir_0, dest_dir_file + ':') - if util.try_makedirs(dest_dir_ros): - # Skip initial header. - in_f.seek(32) + # Parse file entries. + while True: + # Read file entry header. + header = in_f.read(32) + if len(header) != 32: + break + file_size, = struct.unpack(' 1: - self.debug_print('ROS file:', file_name) - out_f = open(os.path.join(dest_dir_ros, file_name), 'wb') - out_f.write(data) - out_f.close() + # Write data. + if len(file_name) > 1: + self.debug_print('ROS file:', file_name) + with open(os.path.join(dest_dir_ros, file_name), 'wb') as out_f: + out_f.write(data) - # Run image converter on the desstination directory. - self.image_extractor.convert_inline(os.listdir(dest_dir_ros), dest_dir_ros) + # Run image converter on the destination directory. + self.image_extractor.convert_inline(os.listdir(dest_dir_ros), dest_dir_ros) - # Don't remove ROS as the analyzer uses it for PhoenixNet detection. - # Just remove the destination directory if it's empty. - util.rmdirs(dest_dir_ros) - - in_f.close() + # Don't remove ROS as the analyzer uses it for PhoenixNet detection. + # Just remove the destination directory if it's empty. + util.rmdirs(dest_dir_ros) # Convert any BIOS logo images in-line (to the same destination directory). self.image_extractor.convert_inline(dest_dir_files, dest_dir_0)