diff --git a/maubot/loader/zip.py b/maubot/loader/zip.py index 323b58a..70cee5a 100644 --- a/maubot/loader/zip.py +++ b/maubot/loader/zip.py @@ -271,10 +271,20 @@ class ZippedPluginLoader(PluginLoader): @classmethod def trash(cls, file_path: str, new_name: str | None = None, reason: str = "error") -> None: if cls.trash_path == "delete": - os.remove(file_path) + try: + os.remove(file_path) + except FileNotFoundError: + pass else: new_name = new_name or f"{int(time())}-{reason}-{os.path.basename(file_path)}" - os.rename(file_path, os.path.abspath(os.path.join(cls.trash_path, new_name))) + try: + os.rename(file_path, os.path.abspath(os.path.join(cls.trash_path, new_name))) + except OSError as e: + cls.log.warning(f"Failed to rename {file_path}: {e} - trying to delete") + try: + os.remove(file_path) + except FileNotFoundError: + pass @classmethod def load_all(cls): diff --git a/maubot/management/api/plugin_upload.py b/maubot/management/api/plugin_upload.py index a1f0dfb..ea4fd1f 100644 --- a/maubot/management/api/plugin_upload.py +++ b/maubot/management/api/plugin_upload.py @@ -90,7 +90,7 @@ async def upload_replacement_plugin( replacement = ( str(new_version) if plugin.meta.version != new_version - else f"{new_version}-ts{int(time())}" + else f"{new_version}-ts{int(time() * 1000)}" ) filename = re.sub( f"{re.escape(str(plugin.meta.version))}(-ts[0-9]+)?", replacement, old_filename