Skip to content

Commit 58f03d0

Browse files
committed
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.
1 parent ea3dbeb commit 58f03d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ def save(self):
365365
self.maxServers = max(servers, self.maxServers)
366366
self.maxClients = max(clients, self.maxClients)
367367

368-
with open(os.path.join("static", "list.json"), "w") as fd:
368+
list_path = os.path.join(app.root_path, app.static_folder, "list.json")
369+
with open(list_path + "~", "w") as fd:
369370
json.dump({
370371
"total": {"servers": servers, "clients": clients},
371372
"total_max": {"servers": self.maxServers, "clients": self.maxClients},
@@ -374,6 +375,7 @@ def save(self):
374375
fd,
375376
indent = "\t" if app.config["DEBUG"] else None
376377
)
378+
os.rename(list_path + "~", list_path)
377379

378380
def update(self, server):
379381
with self.lock:

0 commit comments

Comments
 (0)