Skip to content

Commit

Permalink
unload active plugin before updating or reinstalling it (fix #54968)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed Oct 28, 2023
1 parent 3a22a8e commit 53e3c5d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/pyplugin_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from qgis.core import Qgis, QgsApplication, QgsNetworkAccessManager, QgsSettings, QgsNetworkRequestParameters
from qgis.gui import QgsMessageBar, QgsPasswordLineEdit, QgsHelp
from qgis.utils import (iface, startPlugin, unloadPlugin, loadPlugin, OverrideCursor,
reloadPlugin, updateAvailablePlugins, plugins_metadata_parser)
reloadPlugin, updateAvailablePlugins, plugins_metadata_parser, isPluginLoaded)
from .installer_data import (repositories, plugins, officialRepo,
settingsGroup, reposGroup, removeDir)
from .qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
Expand Down Expand Up @@ -315,13 +315,21 @@ def installPlugin(self, key, quiet=False, stable=True):
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer!"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return

# if plugin is active, unload it before update, see https://github.com/qgis/QGIS/issues/54968
pluginWasLoaded = isPluginLoaded(plugin["id"])
if pluginWasLoaded:
unloadPlugin(plugin["id"])

dlg = QgsPluginInstallerInstallingDialog(iface.mainWindow(), plugin, stable=stable)
dlg.exec_()

plugin_path = qgis.utils.home_plugin_path + "/" + key
if dlg.result():
error = True
infoString = (self.tr("Plugin installation failed"), dlg.result())
# download failed or aborted. If plugin was active before the update, let's try to load it back
if pluginWasLoaded and loadPlugin(plugin["id"]):
startPlugin(plugin["id"])
elif not QDir(plugin_path).exists():
error = True
infoString = (
Expand Down Expand Up @@ -612,6 +620,10 @@ def installFromZipFile(self, filePath):

pluginDirectory = QDir.cleanPath(os.path.join(pluginsDirectory, pluginName))

# if plugin is active, unload it before update, see https://github.com/qgis/QGIS/issues/54968
if isPluginLoaded(pluginName):
unloadPlugin(pluginName)

# If the target directory already exists as a link,
# remove the link without resolving
QFile(pluginDirectory).remove()
Expand Down

0 comments on commit 53e3c5d

Please sign in to comment.