diff options
author | Xavier Delaruelle <xavier.delaruelle@cea.fr> | 2023-04-03 22:54:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 22:54:18 +0200 |
commit | 7a77ecbdb6f2c7cf8bd2855c1def95a734aeccbb (patch) | |
tree | 313d08285167872065e954cb6cb05a53235c5811 | |
parent | 91636f0e9d43c1362a5200753e90b615e21103a2 (diff) | |
download | spack-7a77ecbdb6f2c7cf8bd2855c1def95a734aeccbb.tar.gz spack-7a77ecbdb6f2c7cf8bd2855c1def95a734aeccbb.tar.bz2 spack-7a77ecbdb6f2c7cf8bd2855c1def95a734aeccbb.tar.xz spack-7a77ecbdb6f2c7cf8bd2855c1def95a734aeccbb.zip |
modules: remove default symlink on uninstall (#36454)
When app is uninstalled, if it matches a default, then remove the
default symlink targeting its modulefile.
Until now, when a default were uninstalled, the default symlink were
left pointing to a nonexistent modulefile.
-rw-r--r-- | lib/spack/spack/modules/common.py | 13 | ||||
-rw-r--r-- | lib/spack/spack/test/modules/common.py | 3 |
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): |