diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-09-12 11:37:41 -0400 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-09-12 11:37:41 -0400 |
commit | c52371ecbc62ff39dc1fd362f064d4e50524ee0a (patch) | |
tree | dc0f67f0804606bf1fa3aa9831254b63e8cddac8 | |
parent | 35de2a486f773b24184547d04811f52d6441d716 (diff) | |
download | buildstream-c52371ecbc62ff39dc1fd362f064d4e50524ee0a.tar.gz |
source.py: Use utils.sha256sum() when calculating workspace keys
-rw-r--r-- | buildstream/source.py | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/buildstream/source.py b/buildstream/source.py index bb6121995..09dbae138 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -23,7 +23,6 @@ Source """ import os -import hashlib import tempfile import shutil from contextlib import contextmanager @@ -339,23 +338,20 @@ class Source(Plugin): # Return a list of (relative filename, sha256 digest) tuples, a sorted list # has already been returned by list_relative_paths() - return [(relpath, _sha256sum(fullpath)) for relpath, fullpath in filelist] + return [(relpath, _unique_key(fullpath)) for relpath, fullpath in filelist] # Get the sha256 sum for the content of a file -def _sha256sum(filename): +def _unique_key(filename): - # If it's a directory or symlink, just return 0 string - if os.path.isdir(filename) or os.path.islink(filename): + # If it's a directory, just return 0 string + if os.path.isdir(filename): return "0" + elif os.path.islink(filename): + return "1" - h = hashlib.sha256() try: - with open(filename, "rb") as f: - for chunk in iter(lambda: f.read(4096), b""): - h.update(chunk) + return utils.sha256sum(filename) except FileNotFoundError as e: raise LoadError(LoadErrorReason.MISSING_FILE, "Failed loading workspace. Did you remove the workspace directory? {}".format(e)) - - return h.hexdigest() |