mirror of https://github.com/MISP/MISP-maltego
fix: [galaxies] lock when generating galaxies cache, fixes #23
parent
3e37cdf845
commit
935fba6a43
|
@ -501,6 +501,12 @@ def galaxy_update_local_copy(force=False):
|
||||||
force = True
|
force = True
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
|
# FIXME create a lock to prevent two processes doing the same, and writing to the file at the same time
|
||||||
|
lockfile = local_path_uuid_mapping + '.lock'
|
||||||
|
from pathlib import Path
|
||||||
|
while os.path.exists(lockfile):
|
||||||
|
time.sleep(0.3)
|
||||||
|
Path(local_path_uuid_mapping + '.lock').touch()
|
||||||
# download the latest zip of the public galaxy
|
# download the latest zip of the public galaxy
|
||||||
try:
|
try:
|
||||||
resp = requests.get(galaxy_archive_url)
|
resp = requests.get(galaxy_archive_url)
|
||||||
|
@ -542,7 +548,9 @@ def galaxy_update_local_copy(force=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with open(local_path_uuid_mapping, 'w') as f:
|
with open(local_path_uuid_mapping, 'w') as f:
|
||||||
json.dump(cluster_uuids, f, sort_keys=True, indent=4)
|
json.dump(cluster_uuids, f)
|
||||||
|
# remove the lock
|
||||||
|
os.remove(lockfile)
|
||||||
|
|
||||||
|
|
||||||
def galaxy_load_cluster_mapping():
|
def galaxy_load_cluster_mapping():
|
||||||
|
|
Loading…
Reference in New Issue