diff --git a/maubot/__main__.py b/maubot/__main__.py index 5d5daec..9f8cafe 100644 --- a/maubot/__main__.py +++ b/maubot/__main__.py @@ -58,7 +58,7 @@ loop = asyncio.get_event_loop() init_db(db_session) clients = init_client(loop) -init_plugin_instance_class(db_session, config) +init_plugin_instance_class(db_session, config, loop) management_api = init_management(config, loop) server = MaubotServer(config, management_api, loop) diff --git a/maubot/instance.py b/maubot/instance.py index 924bf5a..51c9dcd 100644 --- a/maubot/instance.py +++ b/maubot/instance.py @@ -129,7 +129,10 @@ class PluginInstance: return self.log.debug("Stopping plugin instance...") self.running = False - await self.plugin.stop() + try: + await self.plugin.stop() + except Exception: + self.log.exception("Failed to stop instance") self.plugin = None @classmethod diff --git a/maubot/loader/zip.py b/maubot/loader/zip.py index c811848..a4f1d6e 100644 --- a/maubot/loader/zip.py +++ b/maubot/loader/zip.py @@ -151,7 +151,7 @@ class ZippedPluginLoader(PluginLoader): def _get_importer(self, reset_cache: bool = False) -> zipimporter: try: - if not self._importer: + if not self._importer or self._importer.archive != self.path: self._importer = zipimporter(self.path) if reset_cache: self._importer.reset_cache() diff --git a/maubot/management/api/plugin.py b/maubot/management/api/plugin.py index d07030c..03fb609 100644 --- a/maubot/management/api/plugin.py +++ b/maubot/management/api/plugin.py @@ -15,8 +15,10 @@ # along with this program. If not, see . from aiohttp import web from io import BytesIO +from time import time import traceback import os.path +import re from ...loader import PluginLoader, ZippedPluginLoader, MaubotZipImportError from .responses import (ErrPluginNotFound, ErrPluginInUse, plugin_import_error, @@ -81,11 +83,14 @@ async def upload_new_plugin(content: bytes, pid: str, version: str) -> web.Respo async def upload_replacement_plugin(plugin: ZippedPluginLoader, content: bytes, new_version: str ) -> web.Response: dirname = os.path.dirname(plugin.path) - filename = os.path.basename(plugin.path) - if plugin.version in filename: - filename = filename.replace(plugin.version, new_version) + old_filename = os.path.basename(plugin.path) + if plugin.version in old_filename: + filename = old_filename.replace(plugin.version, new_version) + if filename == old_filename: + filename = re.sub(f"{re.escape(plugin.version)}(-ts[0-9]+)?", + f"{new_version}-ts{int(time())}", old_filename) else: - filename = filename.rstrip(".mbp") + filename = old_filename.rstrip(".mbp") filename = f"{filename}-v{new_version}.mbp" path = os.path.join(dirname, filename) with open(path, "wb") as p: