From e3b0ca8ef65b389bc5af21b3efaef703766d8ae6 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 12 Apr 2025 10:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=AF=94=E8=BE=83=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E4=BB=BB=E6=84=8F=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E7=9A=84=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/zip_updator.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/astrbot/core/zip_updator.py b/astrbot/core/zip_updator.py index 7a27c1940..844de428e 100644 --- a/astrbot/core/zip_updator.py +++ b/astrbot/core/zip_updator.py @@ -105,16 +105,24 @@ class RepoZipUpdator: """ 比较两个版本号的大小。 返回 1 表示 v1 > v2,返回 -1 表示 v1 < v2,返回 0 表示 v1 = v2。 + 支持任意长度的版本号,如v1.2.3或v3.5.3.1。 """ v1 = v1.replace("v", "") v2 = v2.replace("v", "") - v1 = v1.split(".") - v2 = v2.split(".") + v1_parts = v1.split(".") + v2_parts = v2.split(".") - for i in range(3): - if int(v1[i]) > int(v2[i]): + # 获取最长的版本号长度 + length = max(len(v1_parts), len(v2_parts)) + + # 将短版本号补0以便比较 + v1_parts.extend(["0"] * (length - len(v1_parts))) + v2_parts.extend(["0"] * (length - len(v2_parts))) + + for i in range(length): + if int(v1_parts[i]) > int(v2_parts[i]): return 1 - elif int(v1[i]) < int(v2[i]): + elif int(v1_parts[i]) < int(v2_parts[i]): return -1 return 0