summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-05-23 14:56:35 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-05-23 14:56:35 +0000
commit91c3000ba542efa8540aabce4990d6c8bd7ac858 (patch)
tree9095a67adb0db846e93fd25e67064db74e524bc4
parent156affd4a33562bd383b5fc598fb95b9f99da0ea (diff)
parent45d3cf7f048571abc8e45ed7f14e27852042eca5 (diff)
downloadbuildstream-91c3000ba542efa8540aabce4990d6c8bd7ac858.tar.gz
Merge branch 'juerg/atomic-artifact' into 'master'
Create artifact proto files atomically See merge request BuildStream/buildstream!1354
-rw-r--r--src/buildstream/_artifact.py2
-rw-r--r--src/buildstream/_artifactcache.py2
-rw-r--r--src/buildstream/_cas/casserver.py3
3 files changed, 4 insertions, 3 deletions
diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py
index b3ef005f0..90d25b4fe 100644
--- a/src/buildstream/_artifact.py
+++ b/src/buildstream/_artifact.py
@@ -183,7 +183,7 @@ class Artifact():
keys = utils._deduplicate([self._cache_key, self._weak_cache_key])
for key in keys:
path = os.path.join(self._artifactdir, element.get_artifact_name(key=key))
- with open(path, mode='w+b') as f:
+ with utils.save_file_atomic(path, mode='wb') as f:
f.write(artifact.SerializeToString())
return size
diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py
index 091b44dda..91ff762c7 100644
--- a/src/buildstream/_artifactcache.py
+++ b/src/buildstream/_artifactcache.py
@@ -611,7 +611,7 @@ class ArtifactCache(BaseCache):
# Write the artifact proto to cache
artifact_path = os.path.join(self.artifactdir, request.cache_key)
os.makedirs(os.path.dirname(artifact_path), exist_ok=True)
- with open(artifact_path, 'w+b') as f:
+ with utils.save_file_atomic(artifact_path, mode='wb') as f:
f.write(artifact.SerializeToString())
return True
diff --git a/src/buildstream/_cas/casserver.py b/src/buildstream/_cas/casserver.py
index c08a4d577..e3a69c77f 100644
--- a/src/buildstream/_cas/casserver.py
+++ b/src/buildstream/_cas/casserver.py
@@ -37,6 +37,7 @@ from .._protos.google.rpc import code_pb2
from .._protos.buildstream.v2 import buildstream_pb2, buildstream_pb2_grpc, \
artifact_pb2, artifact_pb2_grpc
+from .. import utils
from .._exceptions import CASError
from .cascache import CASCache
@@ -474,7 +475,7 @@ class _ArtifactServicer(artifact_pb2_grpc.ArtifactServiceServicer):
# Add the artifact proto to the cas
artifact_path = os.path.join(self.artifactdir, request.cache_key)
os.makedirs(os.path.dirname(artifact_path), exist_ok=True)
- with open(artifact_path, 'wb') as f:
+ with utils.save_file_atomic(artifact_path, mode='wb') as f:
f.write(artifact.SerializeToString())
return artifact