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.
This commit is contained in:
ShadowNinja
2016-02-04 16:49:25 -05:00
parent ea3dbeb889
commit 58f03d0395

View File

@@ -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: