Skip to content

Commit 8e1d44c

Browse files
authored
Added health checks to ABSettings (#1337)
1 parent 8d33650 commit 8e1d44c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

activity_browser/settings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ def __init__(self, filename: str):
7272

7373
super().__init__(ab_dir.user_data_dir, filename)
7474

75+
if not self.healthy():
76+
log.warn("Settings health check failed, resetting")
77+
self.restore_default_settings()
78+
79+
def healthy(self) -> bool:
80+
"""
81+
Checks the settings file to see if it is healthy. Returns True if all checks pass, otherwise returns False.
82+
"""
83+
healthy = True
84+
85+
# check for write access to the current bw dir
86+
healthy = healthy and os.access(self.settings.get("current_bw_dir"), os.W_OK)
87+
88+
# check for write access to the custom bw dirs
89+
access = [os.access(path, os.W_OK) for path in self.settings.get("custom_bw_dirs")]
90+
healthy = healthy and False not in access
91+
92+
return healthy
93+
7594
@staticmethod
7695
def update_old_settings(directory: str, filename: str) -> None:
7796
"""Recycling code to enable backward compatibility: This function is only required for compatibility

0 commit comments

Comments
 (0)