Skip to content

Commit

Permalink
lsp.py: remove oldest file.
Browse files Browse the repository at this point in the history
Partial work for ghdl-language-server#79
  • Loading branch information
tgingold committed Jul 3, 2021
1 parent 1da694f commit 3f2abaf
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pyGHDL/cli/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@

def __rotate_log_files(basename: str, num: int):
"""Rotate existing log files."""
# Remove the oldest file. This one will be lost.
# Required on Windows as it is an error to rename a file to an existing
# one.
oldfile = "{}.{}".format(basename, num)
if os.path.isfile(oldfile):
os.remove(oldfile)
# Rotate old files
for i in range(num, 0, -1):
oldfile = "{}.{}".format(basename, i - 1)
if os.path.isfile(oldfile):
os.rename(oldfile, "{}.{}".format(basename, i))
# Rotate the newest log file.
if os.path.isfile(basename):
os.rename(basename, "{}.0".format(basename))

Expand Down

0 comments on commit 3f2abaf

Please sign in to comment.