From 00d7012ef9b260f8f6841af7d3681a048285dfd7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 10 Feb 2024 10:58:37 +0000 Subject: [PATCH] Remove federated blocks file if endpoints are removed --- blocking.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/blocking.py b/blocking.py index 4329aa2a7..f5095291c 100644 --- a/blocking.py +++ b/blocking.py @@ -1976,12 +1976,26 @@ def save_block_federated_endpoints(base_dir: str, continue block_federated_endpoints_str += endpoint.strip() + '\n' result.append(endpoint) - try: - with open(block_api_endpoints_filename, 'w+', - encoding='utf-8') as fp_api: - fp_api.write(block_federated_endpoints_str) - except OSError: - print('EX: unable to write block_api_endpoints.txt') + if not block_federated_endpoints_str: + if os.path.isfile(block_api_endpoints_filename): + try: + os.remove(block_api_endpoints_filename) + except OSError: + print('EX: unable to delete block_api_endpoints.txt') + block_api_filename = \ + base_dir + '/accounts/block_api.txt' + if os.path.isfile(block_api_filename): + try: + os.remove(block_api_filename) + except OSError: + print('EX: unable to delete block_api.txt') + else: + try: + with open(block_api_endpoints_filename, 'w+', + encoding='utf-8') as fp_api: + fp_api.write(block_federated_endpoints_str) + except OSError: + print('EX: unable to write block_api_endpoints.txt') return result