Skip to content

Commit ae627d9

Browse files
committed
Make update check work with RCs
1 parent 5f6350c commit ae627d9

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

official/check_for_updates.lua

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,25 @@ dt.configuration.check_version(...,{2,0,0})
3737
-- returns -1, 0, 1 if the first version is smaller, equal, greater than the second version,
3838
-- or nil if one or both are of the wrong format
3939
-- strings like "release-1.2.3" and "1.2.3+456~gb00b5" are fine, too
40+
local function parse_version(s)
41+
local rc = 0
42+
local major, minor, patch = s:match("(%d+)%.(%d+)%.(%d+)")
43+
if not major then
44+
patch = 0
45+
major, minor, rc = s:match("(%d+)%.(%d+)rc(%d+)")
46+
end
47+
if not major then
48+
patch = 0
49+
rc = 0
50+
major, minor = s:match("(%d+)%.(%d+)")
51+
end
52+
return tonumber(major), tonumber(minor), tonumber(patch), tonumber(rc)
53+
end
54+
4055
local function compare_versions(a, b)
41-
local a_major, a_minor, a_patch = a:match("(%d+)%.(%d+)%.(%d+)")
42-
local b_major, b_minor, b_patch = b:match("(%d+)%.(%d+)%.(%d+)")
56+
local a_major, a_minor, a_patch, a_rc = parse_version(a)
57+
local b_major, b_minor, b_patch, b_rc = parse_version(b)
58+
4359
if a_major and a_minor and a_patch and b_major and b_minor and b_patch then
4460
if a_major < b_major then return -1 end
4561
if a_major > b_major then return 1 end
@@ -50,13 +66,43 @@ local function compare_versions(a, b)
5066
if a_patch < b_patch then return -1 end
5167
if a_patch > b_patch then return 1 end
5268

69+
-- when rc == 0 then it's a proper release and newer than the rcs
70+
local m = math.max(a_rc, b_rc) + 1
71+
if a_rc == 0 then a_rc = m end
72+
if b_rc == 0 then b_rc = m end
73+
if a_rc < b_rc then return -1 end
74+
if a_rc > b_rc then return 1 end
75+
5376
return 0
5477
else
5578
return
5679
end
5780
end
5881

5982

83+
-- local function test(a, b, r)
84+
-- local cmp = compare_versions(a, b)
85+
-- if(not cmp) then
86+
-- print(a .. " ./. " .. b .. " => MALFORMED INPUT")
87+
-- elseif(cmp == r) then
88+
-- print(a .. " ./. " .. b .. " => PASSED")
89+
-- else
90+
-- print(a .. " ./. " .. b .. " => FAILED")
91+
-- end
92+
-- end
93+
--
94+
-- test("malformed", "1.0.0", 0)
95+
-- test("2.0rc1+135~ge456b2b-dirty", "release-1.6.9", 1)
96+
-- test("release-1.6.9", "2.0rc1+135~ge456b2b-dirty", -1)
97+
-- test("2.0rc1+135~ge456b2b-dirty", "2.0rc2+135~ge456b2b-dirty", -1)
98+
-- test("2.0rc2+135~ge456b2b-dirty", "2.0rc1+135~ge456b2b-dirty", 1)
99+
-- test("2.0rc3+135~ge456b2b-dirty", "release-2.0", -1)
100+
-- test("2.0rc3+135~ge456b2b-dirty", "release-2.0.0", -1)
101+
-- test("1.0.0", "2.0.0", -1)
102+
-- test("2.0.0", "1.0.0", 1)
103+
-- test("3.0.0", "3.0.0", 0)
104+
105+
60106
-- check stored timestamp and skip the check if the last time was not too long ago
61107
-- for now we are assuming that os.time() returns seconds. that's not guaranteed but the case on many systems.
62108
-- the reference date doesn't matter, as long as it's currently positive (we start with 0 the first time)

0 commit comments

Comments
 (0)