summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Josef Scheibel <scheibel1@llnl.gov>2019-11-26 18:50:32 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-23 23:03:09 -0800
commit98b498c671fe4cec0c3b1ecfc09fa959faa713bd (patch)
tree51693acced52333a7912559030cf30ff456287e3
parent64209dda977c907da435faed6c9e030a50c520ab (diff)
downloadspack-98b498c671fe4cec0c3b1ecfc09fa959faa713bd.tar.gz
spack-98b498c671fe4cec0c3b1ecfc09fa959faa713bd.tar.bz2
spack-98b498c671fe4cec0c3b1ecfc09fa959faa713bd.tar.xz
spack-98b498c671fe4cec0c3b1ecfc09fa959faa713bd.zip
Mirrors: fix cosmetic symlink targets
The targets for the cosmetic paths in mirrrors were being calculated incorrectly as of fb3a3ba: the symlinks used relative paths as targets, and the relative path was computed relative to the wrong directory.
-rw-r--r--lib/spack/spack/caches.py3
-rw-r--r--lib/spack/spack/test/mirror.py32
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/spack/spack/caches.py b/lib/spack/spack/caches.py
index 61a47eaa6e..ce2f8a6371 100644
--- a/lib/spack/spack/caches.py
+++ b/lib/spack/spack/caches.py
@@ -67,8 +67,9 @@ class MirrorCache(object):
storage location."""
cosmetic_path = os.path.join(self.root, mirror_ref.cosmetic_path)
+ storage_path = os.path.join(self.root, mirror_ref.storage_path)
relative_dst = os.path.relpath(
- mirror_ref.storage_path,
+ storage_path,
start=os.path.dirname(cosmetic_path))
if not os.path.exists(cosmetic_path):
diff --git a/lib/spack/spack/test/mirror.py b/lib/spack/spack/test/mirror.py
index 9068db7193..e1b31695e3 100644
--- a/lib/spack/spack/test/mirror.py
+++ b/lib/spack/spack/test/mirror.py
@@ -14,6 +14,8 @@ from spack.spec import Spec
from spack.stage import Stage
from spack.util.executable import which
+from llnl.util.filesystem import resolve_link_target_relative_to_the_link
+
pytestmark = pytest.mark.usefixtures('config', 'mutable_mock_packages')
# paths in repos that shouldn't be in the mirror tarballs.
@@ -192,3 +194,33 @@ def test_mirror_with_url_patches(mock_packages, config, monkeypatch):
'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz' # NOQA: ignore=E501
]) - files_cached_in_mirror)
+
+
+class MockFetcher(object):
+ """Mock fetcher object which implements the necessary functionality for
+ testing MirrorCache
+ """
+ @staticmethod
+ def archive(dst):
+ with open(dst, 'w'):
+ pass
+
+
+@pytest.mark.regression('14067')
+def test_mirror_cache_symlinks(tmpdir):
+ """Confirm that the cosmetic symlink created in the mirror cache (which may
+ be relative) targets the storage path correctly.
+ """
+ cosmetic_path = 'zlib/zlib-1.2.11.tar.gz'
+ global_path = '_source-cache/archive/c3/c3e5.tar.gz'
+ cache = spack.caches.MirrorCache(str(tmpdir))
+ reference = spack.mirror.MirrorReference(cosmetic_path, global_path)
+
+ cache.store(MockFetcher(), reference.storage_path)
+ cache.symlink(reference)
+
+ link_target = resolve_link_target_relative_to_the_link(
+ os.path.join(cache.root, reference.cosmetic_path))
+ assert os.path.exists(link_target)
+ assert (os.path.normpath(link_target) ==
+ os.path.join(cache.root, reference.storage_path))