summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorHolger Levsen <holger@layer-acht.org>2015-03-13 18:29:39 +0100
committerHolger Levsen <holger@layer-acht.org>2015-03-13 18:29:39 +0100
commit9e142f8c980a64d13df65789232807d417234c58 (patch)
tree6eaaf01f0a15c42d5039156f0e263ccb40b96343 /bin
parentb7a303819727cd1dc33705ebdedc88eb79ae35cb (diff)
downloadjenkins.debian.net-9e142f8c980a64d13df65789232807d417234c58.tar.xz
reproducible: write json to tempfile first, so that updates are atomic
Diffstat (limited to 'bin')
-rwxr-xr-xbin/reproducible_json.py9
1 files changed, 8 insertions, 1 deletions
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.')