From d528fd80b418ce3f58a7bf3c13da5db448494df8 Mon Sep 17 00:00:00 2001 From: Tristan Maat Date: Tue, 17 Dec 2019 14:11:36 +0000 Subject: _casbaseddirectory.py: Refactor _add_file For some reason we were directly modifying fields on the object although they can be set comfortably using the constructor. --- src/buildstream/storage/_casbaseddirectory.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py index 624d071dd..04b2a61ca 100644 --- a/src/buildstream/storage/_casbaseddirectory.py +++ b/src/buildstream/storage/_casbaseddirectory.py @@ -158,19 +158,26 @@ class CasBasedDirectory(Directory): return newdir def _add_file(self, basename, filename, modified=False, can_link=False, properties=None): - entry = IndexEntry(filename, _FileType.REGULAR_FILE, modified=modified or filename in self.index) path = os.path.join(basename, filename) - entry.digest = self.cas_cache.add_object(path=path, link_directly=can_link) - entry.is_executable = os.access(path, os.X_OK) - properties = properties or [] + digest = self.cas_cache.add_object(path=path, link_directly=can_link) + is_executable = os.access(path, os.X_OK) + node_properties = [] # see https://github.com/bazelbuild/remote-apis/blob/master/build/bazel/remote/execution/v2/nodeproperties.md # for supported node property specifications - entry.node_properties = [] - if "MTime" in properties: + if properties and "MTime" in properties: node_property = remote_execution_pb2.NodeProperty() node_property.name = "MTime" node_property.value = _get_file_mtimestamp(path) - entry.node_properties.append(node_property) + node_properties.append(node_property) + + entry = IndexEntry( + filename, + _FileType.REGULAR_FILE, + digest=digest, + is_executable=is_executable, + modified=modified or filename in self.index, + node_properties=node_properties, + ) self.index[filename] = entry self.__invalidate_digest() -- cgit v1.2.1