summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDenis Davydov <davydden@gmail.com>2018-12-26 07:22:21 +0100
committerTodd Gamblin <tgamblin@llnl.gov>2018-12-25 22:22:21 -0800
commit39b23d277bc3f8a9f1c85b29fda413007b074427 (patch)
tree95fd10c532a865af466a72ff9e17f2279e69382b /lib
parentd9da7c98a21d3a6bdb2d92b90e53c92c82d5cb2d (diff)
downloadspack-39b23d277bc3f8a9f1c85b29fda413007b074427.tar.gz
spack-39b23d277bc3f8a9f1c85b29fda413007b074427.tar.bz2
spack-39b23d277bc3f8a9f1c85b29fda413007b074427.tar.xz
spack-39b23d277bc3f8a9f1c85b29fda413007b074427.zip
environment: ignore invalid files names in var/spack/environments (#10198)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/environment.py9
-rw-r--r--lib/spack/spack/test/cmd/env.py11
-rw-r--r--lib/spack/spack/test/conftest.py5
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 18bf998438..ad95949d90 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -232,10 +232,15 @@ def get_env(args, cmd_name, required=False):
' spack -e ENV %s ...' % cmd_name)
+def _root(name):
+ """Non-validating version of root(), to be used internally."""
+ return os.path.join(env_path, name)
+
+
def root(name):
"""Get the root directory for an environment by name."""
validate_env_name(name)
- return os.path.join(env_path, name)
+ return _root(name)
def exists(name):
@@ -288,7 +293,7 @@ def all_environment_names():
candidates = sorted(os.listdir(env_path))
names = []
for candidate in candidates:
- yaml_path = os.path.join(root(candidate), manifest_name)
+ yaml_path = os.path.join(_root(candidate), manifest_name)
if valid_env_name(candidate) and os.path.exists(yaml_path):
names.append(candidate)
return names
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 76210bc562..7085373392 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -37,7 +37,7 @@ def test_add():
assert Spec('mpileaks') in e.user_specs
-def test_env_list():
+def test_env_list(mutable_mock_env_path):
env('create', 'foo')
env('create', 'bar')
env('create', 'baz')
@@ -48,6 +48,15 @@ def test_env_list():
assert 'bar' in out
assert 'baz' in out
+ # make sure `spack env list` skips invalid things in var/spack/env
+ mutable_mock_env_path.join('.DS_Store').ensure(file=True)
+ out = env('list')
+
+ assert 'foo' in out
+ assert 'bar' in out
+ assert 'baz' in out
+ assert '.DS_Store' not in out
+
def test_env_remove(capfd):
env('create', 'foo')
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index ad0644da3e..afa210a87a 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -703,8 +703,9 @@ def mock_svn_repository(tmpdir_factory):
def mutable_mock_env_path(tmpdir_factory):
"""Fixture for mocking the internal spack environments directory."""
saved_path = spack.environment.env_path
- spack.environment.env_path = str(tmpdir_factory.mktemp('mock-env-path'))
- yield spack.environment.env_path
+ mock_path = tmpdir_factory.mktemp('mock-env-path')
+ spack.environment.env_path = str(mock_path)
+ yield mock_path
spack.environment.env_path = saved_path