From 9e142f8c980a64d13df65789232807d417234c58 Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Fri, 13 Mar 2015 18:29:39 +0100 Subject: reproducible: write json to tempfile first, so that updates are atomic --- bin/reproducible_json.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/reproducible_json.py b/bin/reproducible_json.py index 3d63a030..d00d5091 100755 --- a/bin/reproducible_json.py +++ b/bin/reproducible_json.py @@ -12,6 +12,9 @@ from reproducible_common import * import json +import os +import tempfile + output = [] @@ -29,8 +32,12 @@ for row in result: log.debug(pkg) output.append(pkg) -with open(REPRODUCIBLE_JSON, 'w') as fd: +tmpfile = tempfile.NamedTemporaryFile(dir=os.path.dirname(REPRODUCIBLE_JSON)) + +with open(tmpfile.name, 'w') as fd: json.dump(output, fd, indent=4, sort_keys=True) +os.rename(tmpfile.name, REPRODUCIBLE_JSON) + log.info(REPRODUCIBLE_URL + '/reproducible.json has been updated.') -- cgit v1.2.3-54-g00ecf