diff options
author | Antoine Wacheux <awacheux@bloomberg.net> | 2017-12-13 08:55:43 +0000 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2017-12-13 17:36:57 +0100 |
commit | 34b43a9f5bfa49c5b19f1a237c7c384e05f57cf8 (patch) | |
tree | 1309baf6bb12c57bdcbfad997c4011ac49d9d584 | |
parent | a93849a36c12320784b1392517423cd2ea9b55d5 (diff) | |
download | buildstream-34b43a9f5bfa49c5b19f1a237c7c384e05f57cf8.tar.gz |
plugins/sources/local.py: Cache the local element's unique key
This avoid multiple file system traversal when the key is requested multiple
times.
-rw-r--r-- | buildstream/plugins/sources/local.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/buildstream/plugins/sources/local.py b/buildstream/plugins/sources/local.py index d513b897e..e2a769e1c 100644 --- a/buildstream/plugins/sources/local.py +++ b/buildstream/plugins/sources/local.py @@ -41,6 +41,12 @@ from buildstream import utils class LocalSource(Source): + def __init__(self, context, project, meta): + super().__init__(context, project, meta) + + # Cached unique key to avoid multiple file system traversal if the unique key is requested multiple times. + self.__unique_key = None + def configure(self, node): self.node_validate(node, ['path'] + Source.COMMON_CONFIG_KEYS) @@ -53,16 +59,18 @@ class LocalSource(Source): raise SourceError("Specified path '{}' does not exist".format(self.path)) def get_unique_key(self): - # Get a list of tuples of the the project relative paths and fullpaths - if os.path.isdir(self.fullpath): - filelist = utils.list_relative_paths(self.fullpath) - filelist = [(relpath, os.path.join(self.fullpath, relpath)) for relpath in filelist] - else: - filelist = [(self.path, self.fullpath)] - - # Return a list of (relative filename, sha256 digest) tuples, a sorted list - # has already been returned by list_relative_paths() - return [(relpath, unique_key(fullpath)) for relpath, fullpath in filelist] + if self.__unique_key is None: + # Get a list of tuples of the the project relative paths and fullpaths + if os.path.isdir(self.fullpath): + filelist = utils.list_relative_paths(self.fullpath) + filelist = [(relpath, os.path.join(self.fullpath, relpath)) for relpath in filelist] + else: + filelist = [(self.path, self.fullpath)] + + # Return a list of (relative filename, sha256 digest) tuples, a sorted list + # has already been returned by list_relative_paths() + self.__unique_key = [(relpath, unique_key(fullpath)) for relpath, fullpath in filelist] + return self.__unique_key def get_consistency(self): return Consistency.CACHED |