This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch aevri/win32_temptext in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit d97f9095597b05d669db3f81c5a6b51bca62392c Author: Angelos Evripiotis <[email protected]> AuthorDate: Thu Jun 6 16:28:10 2019 +0100 _artifact: use _TempTextBuffer instead of tmp file When adding public data to CAS, save on file I/O by passing an in-memory buffer to _cas.add_object() instead of a filename to read. This means that we avoid reading back the file from disk when hashing it, we still only write it to disk once. This also side-steps a win32 compatability issue, the 'name' member of tempfile.NamedTemporaryFile cannot be opened on Windows NT or later, as per the Python docs: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile --- src/buildstream/_artifact.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py index 90d25b4..b0db06d 100644 --- a/src/buildstream/_artifact.py +++ b/src/buildstream/_artifact.py @@ -29,7 +29,6 @@ artifact composite interaction away from Element class """ import os -import tempfile from ._protos.buildstream.v2.artifact_pb2 import Artifact as ArtifactProto from . import _yaml @@ -148,9 +147,9 @@ class Artifact(): size += filesvdir.get_size() # Store public data - with tempfile.NamedTemporaryFile(dir=self._tmpdir) as tmp: - _yaml.dump(_yaml.node_sanitize(publicdata), tmp.name) - public_data_digest = self._cas.add_object(path=tmp.name, link_directly=True) + with utils._TempTextBuffer() as tmp: + _yaml.dump(_yaml.node_sanitize(publicdata), tmp.stream) + public_data_digest = self._cas.add_object(buffer=tmp.get_bytes_copy()) artifact.public_data.CopyFrom(public_data_digest) size += public_data_digest.size_bytes
