From 52076925b82f88eb7a84cfed5d49b6fc376910d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 6 Dec 2022 11:00:01 +0100 Subject: [PATCH] fix: Avoid exception on non-empty directory --- lookyloo/modules/riskiq.py | 5 +++++ lookyloo/modules/urlhaus.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lookyloo/modules/riskiq.py b/lookyloo/modules/riskiq.py index a22323d5..e37ada90 100644 --- a/lookyloo/modules/riskiq.py +++ b/lookyloo/modules/riskiq.py @@ -105,6 +105,11 @@ class RiskIQ(): pdns_info = self.client_dns.get_passive_dns(query=hostname, start=first_seen.isoformat()) if not pdns_info: + try: + url_storage_dir.rmdir() + except OSError: + # Not empty. + pass return pdns_info['results'] = sorted(pdns_info['results'], key=lambda k: k['lastSeen'], reverse=True) with riskiq_file.open('w') as _f: diff --git a/lookyloo/modules/urlhaus.py b/lookyloo/modules/urlhaus.py index dc43cd91..2fc85332 100644 --- a/lookyloo/modules/urlhaus.py +++ b/lookyloo/modules/urlhaus.py @@ -79,7 +79,11 @@ class URLhaus(): if (not url_information or ('query_status' in url_information and url_information['query_status'] == 'no_results')): - url_storage_dir.rmdir() + try: + url_storage_dir.rmdir() + except OSError: + # Not empty. + pass return with uh_file.open('w') as _f: