Skip to content

Commit b6e24aa

Browse files
committed
Add check for empty files if needed content
1 parent 5e7bafe commit b6e24aa

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

utils/startup_check.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
REQUIRED_FILES = {
1818
"data/sniped_codes.txt": "",
19-
"data/privnote_saves.json": {},
20-
"data/sensitive/tokens.json": [],
19+
"data/privnote_saves.json": "{}",
20+
"data/sensitive/tokens.json": "[]",
2121
"themes/ghost.json": DEFAULT_THEME,
2222
"config.json": DEFAULT_CONFIG,
2323
# "ghost.log": ""
@@ -37,6 +37,20 @@ def create_files():
3737
json.dump(content, f, indent=4)
3838
print(f"Created missing file: {path}")
3939

40+
# check contents of files, if they are empty fill them with default values
41+
def check_file_contents():
42+
for path, content in REQUIRED_FILES.items():
43+
if os.path.exists(BASE_PATH + path):
44+
with open(BASE_PATH + path, "r") as f:
45+
file_content = f.read()
46+
if file_content == "" and content != "":
47+
with open(BASE_PATH + path, "w") as f:
48+
if isinstance(content, str):
49+
f.write(content)
50+
else:
51+
json.dump(content, f, indent=4)
52+
print(f"Filled empty file with default content: {path}")
53+
4054
def clear_cache():
4155
for file in os.listdir(BASE_PATH + "data/cache"):
4256
if file not in ["CREATE_WEBHOOKS"]:
@@ -46,6 +60,7 @@ def clear_cache():
4660
def check():
4761
create_directories()
4862
create_files()
63+
check_file_contents()
4964
clear_cache()
5065
print("Startup checks complete.")
5166

0 commit comments

Comments
 (0)