Skip to content

Commit

Permalink
fix (CS): use temporary file for writing configuration to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Dec 10, 2024
1 parent fdbff56 commit b28a214
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/DIRAC/ConfigurationSystem/private/ConfigurationData.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import _thread
import time
import datetime
import secrets

from diraccfg import CFG

Expand Down Expand Up @@ -352,11 +353,15 @@ def __backupCurrentConfiguration(self, backupName):

def writeRemoteConfigurationToDisk(self, backupName=False):
configurationFile = os.path.join(DIRAC.rootPath, "etc", f"{self.getName()}.cfg")
configurationFileTmp = f"{configurationFile}.{secrets.token_hex(8)}"
try:
with open(configurationFile, "w") as fd:
with open(configurationFileTmp, "w") as fd:
fd.write(str(self.remoteCFG))
os.rename(configurationFileTmp, configurationFile)
except Exception as e:
gLogger.fatal("Cannot write new configuration to disk!", f"file {configurationFile} exception {repr(e)}")
if os.path.isfile(configurationFileTmp):
os.remove(configurationFileTmp)
return S_ERROR(f"Can't write cs file {configurationFile}!: {repr(e).replace(',)', ')')}")
if backupName:
self.__backupCurrentConfiguration(backupName)
Expand Down

0 comments on commit b28a214

Please sign in to comment.