Skip to content

Commit

Permalink
Merge pull request DIRACGrid#7947 from DIRACGridBot/cherry-pick-2-dd7…
Browse files Browse the repository at this point in the history
…065e4a-integration

[sweep:integration] Make writing the CS atomic
  • Loading branch information
chrisburr authored Dec 13, 2024
2 parents af2786a + 88f16a1 commit d4c3de2
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 d4c3de2

Please sign in to comment.