From 763346040bfdc099e05590026dfb722f0b7ebca8 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Mon, 1 Dec 2014 12:09:27 +0000 Subject: [PATCH] Create a .new json file, and move, to avoid invalid JSON files on error --- statsrunner/gitaggregate-publisher.py | 3 ++- statsrunner/gitaggregate.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/statsrunner/gitaggregate-publisher.py b/statsrunner/gitaggregate-publisher.py index f671016a11f..a02dbce7738 100644 --- a/statsrunner/gitaggregate-publisher.py +++ b/statsrunner/gitaggregate-publisher.py @@ -40,5 +40,6 @@ total[k][commit] = v for k,v in total.items(): - with open(os.path.join(git_out_dir, k+'.json'), 'w') as fp: + with open(os.path.join(git_out_dir, k+'.json.new'), 'w') as fp: json.dump(v, fp, sort_keys=True, indent=2, default=decimal_default) + os.rename(os.path.join(git_out_dir, k+'.json.new'), os.path.join(git_out_dir, k+'.json')) diff --git a/statsrunner/gitaggregate.py b/statsrunner/gitaggregate.py index 54f97aa8daa..8ffcbb9ae08 100644 --- a/statsrunner/gitaggregate.py +++ b/statsrunner/gitaggregate.py @@ -38,5 +38,6 @@ total[k][commit] = v for k,v in total.items(): - with open(os.path.join(git_out_dir, k+'.json'), 'w') as fp: + with open(os.path.join(git_out_dir, k+'.json.new'), 'w') as fp: json.dump(v, fp, sort_keys=True, indent=2, default=decimal_default) + os.rename(os.path.join(git_out_dir, k+'.json.new'), os.path.join(git_out_dir, k+'.json'))