From 58f03d0395b3abae6e7181bf64e980d716f0f55b Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 4 Feb 2016 16:49:25 -0500 Subject: [PATCH] Try to fix list corruption issue Sometimes the list was send in a corrupted form. This appeared to be the result of overwriting the file as it was being read by the server. This commit tries to fix this by saving to a temporary file and then moving it over the served file. --- server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index b729baf..8f5407b 100755 --- a/server.py +++ b/server.py @@ -365,7 +365,8 @@ class ServerList: self.maxServers = max(servers, self.maxServers) self.maxClients = max(clients, self.maxClients) - with open(os.path.join("static", "list.json"), "w") as fd: + list_path = os.path.join(app.root_path, app.static_folder, "list.json") + with open(list_path + "~", "w") as fd: json.dump({ "total": {"servers": servers, "clients": clients}, "total_max": {"servers": self.maxServers, "clients": self.maxClients}, @@ -374,6 +375,7 @@ class ServerList: fd, indent = "\t" if app.config["DEBUG"] else None ) + os.rename(list_path + "~", list_path) def update(self, server): with self.lock: