summaryrefslogtreecommitdiffstats
path: root/upstream/mate.lua
blob: 08224a49dd231b5d1a22d19ea0b86401c3671c15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
http = require("socket.http")
apk = require("apk")

local M = {}

local cache = {}

local function read_mate_packages(mate_ver)
	local t = {}
	local shaurl = "http://pub.mate-desktop.org/releases/"..mate_ver.."/SHA1SUMS"
	local shadata = assert(http.request(shaurl))

	for hex,name,ver in string.gmatch(shadata,
		"([0-9a-fA-F]+)%s+([^\n]+)-([0-9.]+)%.tar%.xz\n") do

		print(name, ver)
		local v = t[name] or "0"
		if apk.version_compare(v, ver) == "<" then
			t[name] = ver
		end
	end
	return t
end

local function find_newer(self)
	local oldver = self.pkg.pkgver
	if cache[self.mate_ver] == nil then
		cache[self.mate_ver] = read_mate_packages(self.mate_ver)
	end
	local v = cache[self.mate_ver][self.pkg.pkgname]
	if v == nil then
		print(("DEBUG: %s: not in mate list"):format(self.pkg.pkgname))
	end
	if v and apk.version_compare(self.pkg.pkgver, v) == "<" then
		return v
	end
	return nil
end

function M.init(pkg)
	for source in pkg:remote_sources() do
		local mate_ver = source:match("mate%-desktop%.org/releases/([^/]+)/")

		if mate_ver then
			return {
				provider_name = "mate",
				mate_ver = mate_ver,
				find_newer = find_newer,
				pkg = pkg
			}
		end
	end
	return nil
end

return M