Skip to content

Commit

Permalink
Fix #7142: Change manifest update process
Browse files Browse the repository at this point in the history
Earlier, interrupting the manifest-update could end up
causing errors due to the non-atomicity of the process.
Used tempfile to ensure that the file is written correctly.
  • Loading branch information
vedantc98 committed Feb 17, 2018
1 parent 1a2e430 commit 4a5f28e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tools/manifest/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,14 @@ def load(tests_root, manifest):


def write(manifest, manifest_path):
from tempfile import NamedTemporaryFile

dir_name = os.path.dirname(manifest_path)
if not os.path.exists(dir_name):
os.makedirs(dir_name)
with open(manifest_path, "wb") as f:
json.dump(manifest.to_json(), f, sort_keys=True, indent=1, separators=(',', ': '))
f.write("\n")

temp_manifest = NamedTemporaryFile(mode="wb", dir=dir_name)
json.dump(manifest.to_json(), temp_manifest.file,
sort_keys=True, indent=1, separators=(',', ': '))
temp_manifest.write("\n")
os.rename(temp_manifest.name, manifest_path)

0 comments on commit 4a5f28e

Please sign in to comment.