Merge branch 'jeremiah-c-leary:master' into issue-1295

This commit is contained in:
Jukka Hertzog 2024-12-07 13:57:41 +00:00 committed by GitHub
commit 2da3fa68ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -2,6 +2,7 @@
import os
import shutil
import stat
from . import config, junit, rule_list, utils, vhdlFile
from .exceptions import ClassifyError, ConfigurationError
@ -137,10 +138,12 @@ def apply_rules(commandLineArguments, oConfig, tIndexFileName):
def write_vhdl_file(oVhdlFile, dConfig):
tmpfile = f"{oVhdlFile.filename}.tmp"
myStat = os.stat(oVhdlFile.filename)
try:
with open(tmpfile, "w", encoding="utf-8", newline=dConfig.get("linesep")) as oFile:
oFile.write("\n".join(oVhdlFile.get_lines()[1:]))
oFile.write("\n")
os.chmod(tmpfile, myStat.st_mode)
os.replace(tmpfile, oVhdlFile.filename)
except PermissionError as err:
print(err, "Could not write fixes back to file.")