From: Ian Jackson Date: Thu, 7 Nov 2019 00:42:02 +0000 (+0000) Subject: make-secnet-sites: Write output to ...~tmp~ and rename X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=672d4525ebe7dcbcdadcd8c9c964da1ce6aa483d;p=secnet.git make-secnet-sites: Write output to ...~tmp~ and rename This avoids leaving a truncated output file if we crash. It also avoids concurrent readers ever seeing a truncated output file. Signed-off-by: Ian Jackson --- diff --git a/make-secnet-sites b/make-secnet-sites index 66b4cb1..574eb20 100755 --- a/make-secnet-sites +++ b/make-secnet-sites @@ -211,6 +211,7 @@ def parse_args(): global header global groupfiledir global sitesfile + global outputfile global group global user global of @@ -258,8 +259,6 @@ def parse_args(): print("Too many arguments") sys.exit(1) (inputfile, outputfile) = (av.arg + [None]*2)[0:2] - if outputfile is None: of=sys.stdout - else: of=open(outputfile,'w') parse_args() @@ -776,4 +775,11 @@ if service: f.close() os.rename(sitesfile+"-tmp",sitesfile) else: + if outputfile is None: + of=sys.stdout + else: + tmp_outputfile=outputfile+'~tmp~' + of=open(tmp_outputfile,'w') outputsites(of) + if outputfile is not None: + os.rename(tmp_outputfile,outputfile)