fix OSError: [WinError 6] The handle is invalid' - add try/except in rar file extractall() - possible issue with rar5 files

This commit is contained in:
2024-02-23 18:03:13 +00:00
parent 196e215133
commit 0841a1a478

View File

@@ -39,8 +39,11 @@ def extract_rar(rar_file: str, target_dir: str) -> None:
rarfile.UNRAR_TOOL = 'unrar' rarfile.UNRAR_TOOL = 'unrar'
files = rar_ref.namelist() files = rar_ref.namelist()
files = [ f for f in files if "__MACOSX" not in f ] # filter out files with "__MACOSX" in the name files = [ f for f in files if "__MACOSX" not in f ] # filter out files with "__MACOSX" in the name
try:
rar_ref.extractall(target_dir, files) # extract the remaining files rar_ref.extractall(target_dir, files) # extract the remaining files
rar_ref.close() rar_ref.close()
except OSError:
mark_file_as_BAD(rar_file, e)
except rarfile.BadRarFile as e: except rarfile.BadRarFile as e:
mark_file_as_BAD(rar_file, e) mark_file_as_BAD(rar_file, e)
except rarfile.NotRarFile as e: except rarfile.NotRarFile as e: