Skip to content

Commit

Permalink
Create a .new json file, and move, to avoid invalid JSON files on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Dec 1, 2014
1 parent cf32728 commit 7633460
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion statsrunner/gitaggregate-publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
3 changes: 2 additions & 1 deletion statsrunner/gitaggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

0 comments on commit 7633460

Please sign in to comment.