Switch BIOSExtractor header file copying to hardlinks where supported

This commit is contained in:
RichardG867
2022-04-13 22:14:11 -03:00
parent 90a4aefd4d
commit 734dcd38fe
2 changed files with 18 additions and 7 deletions

View File

@@ -406,12 +406,11 @@ class BIOSExtractor(Extractor):
# treat it as a big chunk of data.
open(os.path.join(dest_dir_0, ':combined:'), 'wb').close()
# Copy any header file to extracted directory, for identifying Intel BIOSes.
# See AMIAnalyzer.can_handle for more information.
try:
shutil.copy(os.path.join(os.path.dirname(file_path_abs), ':header:'), os.path.join(dest_dir_0, ':header:'))
except:
pass
# Hardlink or copy any header file to extracted directory, to help with
# identifying Intel BIOSes. See AMIAnalyzer.can_handle for more information.
parent_header = os.path.join(os.path.dirname(file_path_abs), ':header:')
if os.path.exists(parent_header):
util.hardlink_or_copy(parent_header, os.path.join(dest_dir_0, ':header:'))
# Remove BIOS file.
try:

View File

@@ -15,7 +15,7 @@
#
# Copyright 2021 RichardG.
#
import multiprocessing, os, math, re, traceback, urllib.request
import multiprocessing, os, math, re, shutil, traceback, urllib.request
from biostools.pciutil import *
date_pattern_mmddyy = re.compile('''(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<year>[0-9]{2,4})''')
@@ -131,6 +131,18 @@ def date_lt(date1, date2, pattern):
Date format set by the given pattern."""
return date_cmp(date1, date2, pattern) < 0
def hardlink_or_copy(src, dest):
"""Attempt to hardlink or copy src to dest.
Returns True if either operation was successful."""
try:
os.link(src, dest)
except:
try:
shutil.copy2(src, dest)
except:
return False
return True
def log_traceback(*args):
"""Log to biostools_error.log, including any outstanding traceback."""