mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Fix bugs in init and plugin upload filenames
This commit is contained in:
parent
767885cec7
commit
28d7731e70
@ -58,7 +58,7 @@ loop = asyncio.get_event_loop()
|
|||||||
|
|
||||||
init_db(db_session)
|
init_db(db_session)
|
||||||
clients = init_client(loop)
|
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)
|
management_api = init_management(config, loop)
|
||||||
server = MaubotServer(config, management_api, loop)
|
server = MaubotServer(config, management_api, loop)
|
||||||
|
|
||||||
|
@ -129,7 +129,10 @@ class PluginInstance:
|
|||||||
return
|
return
|
||||||
self.log.debug("Stopping plugin instance...")
|
self.log.debug("Stopping plugin instance...")
|
||||||
self.running = False
|
self.running = False
|
||||||
await self.plugin.stop()
|
try:
|
||||||
|
await self.plugin.stop()
|
||||||
|
except Exception:
|
||||||
|
self.log.exception("Failed to stop instance")
|
||||||
self.plugin = None
|
self.plugin = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -151,7 +151,7 @@ class ZippedPluginLoader(PluginLoader):
|
|||||||
|
|
||||||
def _get_importer(self, reset_cache: bool = False) -> zipimporter:
|
def _get_importer(self, reset_cache: bool = False) -> zipimporter:
|
||||||
try:
|
try:
|
||||||
if not self._importer:
|
if not self._importer or self._importer.archive != self.path:
|
||||||
self._importer = zipimporter(self.path)
|
self._importer = zipimporter(self.path)
|
||||||
if reset_cache:
|
if reset_cache:
|
||||||
self._importer.reset_cache()
|
self._importer.reset_cache()
|
||||||
|
@ -15,8 +15,10 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from time import time
|
||||||
import traceback
|
import traceback
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
|
|
||||||
from ...loader import PluginLoader, ZippedPluginLoader, MaubotZipImportError
|
from ...loader import PluginLoader, ZippedPluginLoader, MaubotZipImportError
|
||||||
from .responses import (ErrPluginNotFound, ErrPluginInUse, plugin_import_error,
|
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
|
async def upload_replacement_plugin(plugin: ZippedPluginLoader, content: bytes, new_version: str
|
||||||
) -> web.Response:
|
) -> web.Response:
|
||||||
dirname = os.path.dirname(plugin.path)
|
dirname = os.path.dirname(plugin.path)
|
||||||
filename = os.path.basename(plugin.path)
|
old_filename = os.path.basename(plugin.path)
|
||||||
if plugin.version in filename:
|
if plugin.version in old_filename:
|
||||||
filename = filename.replace(plugin.version, new_version)
|
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:
|
else:
|
||||||
filename = filename.rstrip(".mbp")
|
filename = old_filename.rstrip(".mbp")
|
||||||
filename = f"{filename}-v{new_version}.mbp"
|
filename = f"{filename}-v{new_version}.mbp"
|
||||||
path = os.path.join(dirname, filename)
|
path = os.path.join(dirname, filename)
|
||||||
with open(path, "wb") as p:
|
with open(path, "wb") as p:
|
||||||
|
Loading…
Reference in New Issue
Block a user