Skip to content

Commit

Permalink
Clean up .bin file with or without compress mode
Browse files Browse the repository at this point in the history
  • Loading branch information
k-matsuzaki committed Jul 19, 2024
1 parent 103251c commit e42f07a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions server-python/cgos/app/cgos.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,22 +532,26 @@ def saveSgf(gid: int, game: Game, sc: Optional[str], err: str) -> None:
f.write(comp)
os.replace(f"{dest_dir}/{gid}.bin.tmp", f"{dest_dir}/{gid}.bin")

temp_files = [f"{dest_dir}/{gid}.bin"]

if cfg.compressSgf:
with gzip.open(f"{dest_dir}/{gid}.sgf.gz.tmp", "wb") as f:
f.write(sgfString.encode(ENCODING))
os.replace(f"{dest_dir}/{gid}.sgf.gz.tmp", f"{dest_dir}/{gid}.sgf.gz")
# Clean up
if sc is not None:
for file in [f"{dest_dir}/{gid}.bin", f"{dest_dir}/{gid}.sgf"]:
try:
os.remove(file)
except OSError:
pass
temp_files.append(f"{dest_dir}/{gid}.sgf")
else:
with open(f"{dest_dir}/{gid}.sgf.tmp", "wb") as f:
f.write(sgfString.encode(ENCODING))
os.replace(f"{dest_dir}/{gid}.sgf.tmp", f"{dest_dir}/{gid}.sgf")

# Clean up
if sc is not None:
for file in temp_files:
try:
os.remove(file)
except OSError:
pass


def gameover(gid: int, sc: str, err: str) -> None:
global games
Expand Down

0 comments on commit e42f07a

Please sign in to comment.