Skip to content

Commit

Permalink
sweep: DIRACGrid#7946 Make writing the CS atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr authored and web-flow committed Dec 12, 2024
1 parent af2786a commit 88f16a1
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 @@ -342,11 +343,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 88f16a1

Please sign in to comment.