Skip to content

Commit 28a7a5c

Browse files
committed
Re-use binary loaders which have been written to temporary directory
1 parent bbdc554 commit 28a7a5c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

miner/fsd_binary.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def get_data(self, container_name, language=None, verbose=False, **kwargs):
6262
sys.path.insert(0, temp_dir)
6363

6464
loader_dest = os.path.join(temp_dir, loader_filename)
65-
shutil.copyfile(loader_info.file_abspath, loader_dest)
65+
if not os.path.isfile(loader_dest) or not self._compare_files(loader_info.file_abspath, loader_dest):
66+
shutil.copyfile(loader_info.file_abspath, loader_dest)
6667

6768
loader_modname = os.path.splitext(loader_filename)[0]
6869
loader_module = importlib.import_module(loader_modname)
@@ -119,6 +120,10 @@ def on_error(*args, **kwargs):
119120
if not error_data:
120121
self.__temp_dir = None
121122

123+
def _compare_files(self, file1_path, file2_path):
124+
with open(file1_path, 'rb') as f1, open(file2_path, 'rb') as f2:
125+
return f1.read() == f2.read()
126+
122127

123128
class PlatformError(Exception):
124129
"""Raised when FSD binary miner is used on incorrect platform."""

0 commit comments

Comments
 (0)