From ec19e1deb757a71a00ab6f8b92d9cd1a965a2ab2 Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Fri, 6 Dec 2024 15:30:17 -0600 Subject: [PATCH] Issue#1286: Ensuring existing file permissions are maintained on fixed files. (#1342) --- vsg/apply_rules.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vsg/apply_rules.py b/vsg/apply_rules.py index 25fac1dd..8d3f4524 100644 --- a/vsg/apply_rules.py +++ b/vsg/apply_rules.py @@ -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.")