From 7d88d83c366db56790dfe8d5d798341c521763fa Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 12 Feb 2021 17:00:35 +0100 Subject: [PATCH] handle empty file --- owrx/users.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/owrx/users.py b/owrx/users.py index d866585..2f2e88d 100644 --- a/owrx/users.py +++ b/owrx/users.py @@ -149,7 +149,12 @@ class UserList(object): return "{data_directory}/users.json".format(data_directory=config.get_data_directory()) def _getUsersFileModifiedTimestamp(self): - return datetime.fromtimestamp(os.path.getmtime(self._getUsersFile()), timezone.utc) + timestamp = 0 + try: + timestamp = os.path.getmtime(self._getUsersFile()) + except FileNotFoundError: + pass + return datetime.fromtimestamp(timestamp, timezone.utc) def _loadUsers(self): usersFile = self._getUsersFile() @@ -164,6 +169,7 @@ class UserList(object): self.file_modified = modified return users except FileNotFoundError: + self.file_modified = modified return {} except json.JSONDecodeError: logger.exception("error while parsing users file %s", usersFile)