Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance detection of plugins removed in transaction (RhBug:1929163) #1732

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions dnf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,32 @@ def _unload(self):
del sys.modules[DYNAMIC_PACKAGE]

def unload_removed_plugins(self, transaction):
erased = set([package.name for package in transaction.remove_set])
if not erased:
"""
Unload plugins that were removed in the `transaction`.
"""
if not transaction.remove_set:
return
installed = set([package.name for package in transaction.install_set])
transaction_diff = erased - installed
if not transaction_diff:
return
files_erased = set()

# gather all installed plugins and their files
plugins = dict()
for plugin in self.plugins:
plugins[inspect.getfile(plugin.__class__)] = plugin

# gather all removed files that are plugin files
plugin_files = set(plugins.keys())
erased_plugin_files = set()
for pkg in transaction.remove_set:
if pkg.name in transaction_diff:
files_erased.update(pkg.files)
for plugin in self.plugins[:]:
if inspect.getfile(plugin.__class__) in files_erased:
self.plugins.remove(plugin)
erased_plugin_files.update(plugin_files.intersection(pkg.files))
if not erased_plugin_files:
return

# check whether removed plugin file is added at the same time (upgrade of a plugin)
for pkg in transaction.install_set:
erased_plugin_files.difference_update(pkg.files)

# unload plugins that were removed in transaction
for plugin_file in erased_plugin_files:
self.plugins.remove(plugins[plugin_file])


def _plugin_classes():
Expand Down