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.
This commit is contained in:
committed by
GitHub
parent
91636f0e9d
commit
7a77ecbdb6
@@ -935,6 +935,7 @@ def remove(self):
|
|||||||
if os.path.exists(mod_file):
|
if os.path.exists(mod_file):
|
||||||
try:
|
try:
|
||||||
os.remove(mod_file) # Remove the module file
|
os.remove(mod_file) # Remove the module file
|
||||||
|
self.remove_module_defaults() # Remove default targeting module file
|
||||||
os.removedirs(
|
os.removedirs(
|
||||||
os.path.dirname(mod_file)
|
os.path.dirname(mod_file)
|
||||||
) # Remove all the empty directories from the leaf up
|
) # Remove all the empty directories from the leaf up
|
||||||
@@ -942,6 +943,18 @@ def remove(self):
|
|||||||
# removedirs throws OSError on first non-empty directory found
|
# removedirs throws OSError on first non-empty directory found
|
||||||
pass
|
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
|
@contextlib.contextmanager
|
||||||
def disable_modules():
|
def disable_modules():
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ def test_modules_default_symlink(
|
|||||||
assert os.path.islink(link_path)
|
assert os.path.islink(link_path)
|
||||||
assert os.readlink(link_path) == mock_module_filename
|
assert os.readlink(link_path) == mock_module_filename
|
||||||
|
|
||||||
|
generator.remove()
|
||||||
|
assert not os.path.lexists(link_path)
|
||||||
|
|
||||||
|
|
||||||
class MockDb(object):
|
class MockDb(object):
|
||||||
def __init__(self, db_ids, spec_hash_to_db):
|
def __init__(self, db_ids, spec_hash_to_db):
|
||||||
|
|||||||
Reference in New Issue
Block a user