2
0
mirror of https://github.com/koreader/koreader synced 2024-11-11 19:11:14 +00:00

normalize version when checking packages in OTA manager

This fixes a bug that version 987 was treated newer than version 1010.
This commit is contained in:
chrox 2014-11-10 20:21:25 +08:00
parent 26467d557f
commit befa3aa63c

View File

@ -77,14 +77,25 @@ function OTAManager:checkUpdate()
end end
zsync:close() zsync:close()
end end
local local_version = io.open("git-rev", "r"):read() local normalized_version = function(rev)
local ota_version = nil local version = rev:match("(v%d.-)-g"):gsub("[^%d]", "")
if ota_package then return tonumber(version)
ota_version = ota_package:match(".-(v%d.-)%.tar")
end end
local local_ok, local_version = pcall(function()
local rev_file = io.open("git-rev", "r")
if rev_file then
local rev = rev_file:read()
rev_file:close()
return normalized_version(rev)
end
end)
local ota_ok, ota_version = pcall(function()
return normalized_version(ota_package)
end)
-- return ota package version if package on OTA server has version -- return ota package version if package on OTA server has version
-- larger than the local package version -- larger than the local package version
if ota_version and ota_version > local_version then if local_ok and ota_ok and ota_version and local_version and
ota_version > local_version then
return ota_version return ota_version
elseif ota_version and ota_version == local_version then elseif ota_version and ota_version == local_version then
return 0 return 0