summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2017-12-19 11:59:15 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2018-01-04 12:30:12 +0000
commitc666e70c5f74869c961bba9b57563c8136387d84 (patch)
treee5e2e7d08c75e61910cae8409ed551d1bfd26167
parent3628cbbe0ec04e4f6e202d473a04a8fb3cf60840 (diff)
downloadbuildstream-sam/savefile-utility.tar.gz
_yaml.py: Use save_file_atomic() when writing out YAMLsam/savefile-utility
This makes writes done by `bst track` atomic, meaning a crash or power loss while overwriting a .bst file should never cause the the contents of that file to be lost or partially written.
-rw-r--r--buildstream/_yaml.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 8e51050c3..7bb9b7867 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -26,6 +26,7 @@ from contextlib import ExitStack
from ruamel import yaml
from ruamel.yaml.representer import SafeRepresenter, RoundTripRepresenter
from ._exceptions import LoadError, LoadErrorReason
+from . import utils
# We store information in the loaded yaml on a DictProvenance
@@ -213,7 +214,7 @@ def load_data(data, shortname=None, copy_tree=False):
def dump(node, filename=None):
with ExitStack() as stack:
if filename:
- f = stack.enter_context(open(filename, 'w'))
+ f = stack.enter_context(utils.save_file_atomic(filename, 'w'))
else:
f = sys.stdout
yaml.round_trip_dump(node, f)