From 90a31c45ee2fc1c4c160f029c94be0911d14a8f5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 17 Mar 2023 10:18:17 +0000 Subject: [PATCH] Check that the noannounce file exists --- blocking.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/blocking.py b/blocking.py index 111459d8d..f43474834 100644 --- a/blocking.py +++ b/blocking.py @@ -720,6 +720,11 @@ def allowed_announce_add(base_dir: str, nickname: str, domain: str, """ account_dir = acct_dir(base_dir, nickname, domain) blocking_filename = account_dir + '/noannounce.txt' + + # if the noannounce.txt file doesn't yet exist + if not os.path.isfile(blocking_filename): + return + handle = following_nickname + '@' + following_domain if text_in_file(handle + '\n', blocking_filename, False): file_text = '' @@ -756,6 +761,19 @@ def allowed_announce_remove(base_dir: str, nickname: str, domain: str, account_dir = acct_dir(base_dir, nickname, domain) blocking_filename = account_dir + '/noannounce.txt' handle = following_nickname + '@' + following_domain + + # if the noannounce.txt file doesn't yet exist + if not os.path.isfile(blocking_filename): + file_text = handle + '\n' + try: + with open(blocking_filename, 'w+', + encoding='utf-8') as fp_noannounce: + fp_noannounce.write(file_text) + except OSError: + print('EX: unable to write initial noannounce: ' + + blocking_filename + ' ' + handle) + return + file_text = '' if not text_in_file(handle + '\n', blocking_filename, False): try: