diff options
author | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-10-03 11:37:51 +0100 |
---|---|---|
committer | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-10-29 11:09:52 +0000 |
commit | 0e6901c8e74d6d2da7d2a1f03261f2379c444777 (patch) | |
tree | 41b82e40636a648bfdfcb30d87032159ce551edb | |
parent | 64763b3c4d96aaeff8e14b7fdcba73a51e0f4b03 (diff) | |
download | buildstream-0e6901c8e74d6d2da7d2a1f03261f2379c444777.tar.gz |
_casbaseddirectory: Optionally resolve absolute symlinks
-rw-r--r-- | buildstream/storage/_casbaseddirectory.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/buildstream/storage/_casbaseddirectory.py b/buildstream/storage/_casbaseddirectory.py index 388b8ece6..ef7bb689f 100644 --- a/buildstream/storage/_casbaseddirectory.py +++ b/buildstream/storage/_casbaseddirectory.py @@ -38,6 +38,8 @@ from .._exceptions import BstError from .directory import Directory, VirtualDirectoryError from ._filebaseddirectory import FileBasedDirectory from ..utils import FileListResult, safe_copy, list_relative_paths +from ..utils import FileListResult, safe_copy, list_relative_paths, _relative_symlink_target +from .._artifactcache.cascache import CASCache class IndexEntry(): @@ -285,7 +287,7 @@ class CasBasedDirectory(Directory): directory = directory.descend(c, create=True) return directory - def _resolve(self, name): + def _resolve(self, name, absolute_symlinks_resolve=True): """ Resolves any name to an object. If the name points to a symlink in this directory, it returns the thing it points to, recursively. Returns a CasBasedDirectory, FileNode or None. Never creates a directory or otherwise alters the directory. """ # First check if it's a normal object and return that @@ -304,9 +306,13 @@ class CasBasedDirectory(Directory): absolute = symlink.target.startswith(CasBasedDirectory._pb2_absolute_path_prefix) if absolute: - start_directory = self.find_root() - # Discard the first empty element - components.pop(0) + if absolute_symlinks_resolve: + start_directory = self.find_root() + # Discard the first empty element + components.pop(0) + else: + print(" _resolve: Absolute symlink, which we won't resolve.") + return None else: start_directory = self directory = start_directory @@ -325,7 +331,7 @@ class CasBasedDirectory(Directory): directory = directory.parent else: if c in directory.index: - f = directory._resolve(c) + f = directory._resolve(c, absolute_symlinks_resolve) # Ultimately f must now be a file or directory if isinstance(f, CasBasedDirectory): directory = f @@ -608,7 +614,7 @@ class CasBasedDirectory(Directory): print("Running list_relative_paths on relpath {}. files={}, symlinks={}".format(relpath, [f[0] for f in file_list], [s[0] for s in symlink_list])) for (k, v) in sorted(symlink_list): - target = self._resolve(k) + target = self._resolve(k, absolute_symlinks_resolve=True) if isinstance(target, CasBasedDirectory): print("Adding the resolved symlink {} which resolves to {} to our directory list".format(k, target)) directory_list.append((k,IndexEntry(k, buildstream_object=target))) |