Skip to content

Commit

Permalink
Try to fix list corruption issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ShadowNinja committed Feb 4, 2016
1 parent ea3dbeb commit 58f03d0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server.py
Expand Up @@ -365,7 +365,8 @@ def save(self):
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},
Expand All @@ -374,6 +375,7 @@ def save(self):
fd,
indent = "\t" if app.config["DEBUG"] else None
)
os.rename(list_path + "~", list_path)

def update(self, server):
with self.lock:
Expand Down

0 comments on commit 58f03d0

Please sign in to comment.