diff options
author | Oliver Breitwieser <oliver.breitwieser@kip.uni-heidelberg.de> | 2017-09-18 09:26:08 -0400 |
---|---|---|
committer | scheibelp <scheibel1@llnl.gov> | 2017-11-02 18:45:40 -0700 |
commit | 9024ddcf0536373fe73bfc6ec6fe0c76153d1e7d (patch) | |
tree | 2f863476a044d7aeed801bafd091fab41aa51cf3 /lib | |
parent | 20cd82dc56d015c93e6e326d9ba398f8971e211c (diff) | |
download | spack-9024ddcf0536373fe73bfc6ec6fe0c76153d1e7d.tar.gz spack-9024ddcf0536373fe73bfc6ec6fe0c76153d1e7d.tar.bz2 spack-9024ddcf0536373fe73bfc6ec6fe0c76153d1e7d.tar.xz spack-9024ddcf0536373fe73bfc6ec6fe0c76153d1e7d.zip |
link_tree: support ignoring conflicts
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/llnl/util/link_tree.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/spack/llnl/util/link_tree.py b/lib/spack/llnl/util/link_tree.py index 34a119f570..940526dd5c 100644 --- a/lib/spack/llnl/util/link_tree.py +++ b/lib/spack/llnl/util/link_tree.py @@ -66,8 +66,14 @@ class LinkTree(object): def merge(self, dest_root, **kwargs): """Link all files in src into dest, creating directories - if necessary.""" + if necessary. + If ignore_conflicts is True, do not break when the target exists but + rather return a list of files that could not be linked. + Note that files blocking directories will still cause an error. + """ kwargs['order'] = 'pre' + ignore_conflicts = kwargs.get("ignore_conflicts", False) + existing = [] for src, dest in traverse_tree(self._root, dest_root, **kwargs): if os.path.isdir(src): if not os.path.exists(dest): @@ -83,8 +89,15 @@ class LinkTree(object): touch(marker) else: - assert(not os.path.exists(dest)) - os.symlink(src, dest) + if os.path.exists(dest): + if ignore_conflicts: + existing.append(src) + else: + raise AssertionError("File already exists: %s" % dest) + else: + os.symlink(src, dest) + if ignore_conflicts: + return existing def unmerge(self, dest_root, **kwargs): """Unlink all files in dest that exist in src. |