Handle some more edge cases in plugin upload

This commit is contained in:
Tulir Asokan 2022-03-27 21:01:18 +03:00
parent 106905fd00
commit 55b7730b9e
2 changed files with 13 additions and 3 deletions

View File

@ -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":
try:
os.remove(file_path)
except FileNotFoundError:
pass
else:
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)))
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):

View File

@ -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