summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/modules/common.py13
-rw-r--r--lib/spack/spack/test/modules/common.py3
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py
index 3995233dba..66fe145f35 100644
--- a/lib/spack/spack/modules/common.py
+++ b/lib/spack/spack/modules/common.py
@@ -935,6 +935,7 @@ class BaseModuleFileWriter(object):
if os.path.exists(mod_file):
try:
os.remove(mod_file) # Remove the module file
+ self.remove_module_defaults() # Remove default targeting module file
os.removedirs(
os.path.dirname(mod_file)
) # Remove all the empty directories from the leaf up
@@ -942,6 +943,18 @@ class BaseModuleFileWriter(object):
# removedirs throws OSError on first non-empty directory found
pass
+ def remove_module_defaults(self):
+ if not any(self.spec.satisfies(default) for default in self.conf.defaults):
+ return
+
+ # This spec matches a default, symlink needs to be removed as we remove the module
+ # file it targets.
+ default_symlink = os.path.join(os.path.dirname(self.layout.filename), "default")
+ try:
+ os.unlink(default_symlink)
+ except OSError:
+ pass
+
@contextlib.contextmanager
def disable_modules():
diff --git a/lib/spack/spack/test/modules/common.py b/lib/spack/spack/test/modules/common.py
index 14b6b051a6..0dc12d5bbe 100644
--- a/lib/spack/spack/test/modules/common.py
+++ b/lib/spack/spack/test/modules/common.py
@@ -77,6 +77,9 @@ def test_modules_default_symlink(
assert os.path.islink(link_path)
assert os.readlink(link_path) == mock_module_filename
+ generator.remove()
+ assert not os.path.lexists(link_path)
+
class MockDb(object):
def __init__(self, db_ids, spec_hash_to_db):