mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Handle some more edge cases in plugin upload
This commit is contained in:
parent
106905fd00
commit
55b7730b9e
@ -271,10 +271,20 @@ class ZippedPluginLoader(PluginLoader):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def trash(cls, file_path: str, new_name: str | None = None, reason: str = "error") -> None:
|
def trash(cls, file_path: str, new_name: str | None = None, reason: str = "error") -> None:
|
||||||
if cls.trash_path == "delete":
|
if cls.trash_path == "delete":
|
||||||
|
try:
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
new_name = new_name or f"{int(time())}-{reason}-{os.path.basename(file_path)}"
|
new_name = new_name or f"{int(time())}-{reason}-{os.path.basename(file_path)}"
|
||||||
|
try:
|
||||||
os.rename(file_path, os.path.abspath(os.path.join(cls.trash_path, new_name)))
|
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
|
@classmethod
|
||||||
def load_all(cls):
|
def load_all(cls):
|
||||||
|
@ -90,7 +90,7 @@ async def upload_replacement_plugin(
|
|||||||
replacement = (
|
replacement = (
|
||||||
str(new_version)
|
str(new_version)
|
||||||
if plugin.meta.version != 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(
|
filename = re.sub(
|
||||||
f"{re.escape(str(plugin.meta.version))}(-ts[0-9]+)?", replacement, old_filename
|
f"{re.escape(str(plugin.meta.version))}(-ts[0-9]+)?", replacement, old_filename
|
||||||
|
Loading…
Reference in New Issue
Block a user