e2licence {
gpl_2 = {
- server = "upstream",
+ server = ".",
files = {
- "licence/gpl-2/COPYING",
+ {
+ -- server is inherited if not given here
+ server = ".",
+ location = "licence/gpl-2/COPYING",
+ -- sha1 is required when the server is not "."
+ -- sha1 = "bd3c28b6df9c950cc68d5141c65acfc661779f5e",
+ },
}
}
}
e2lib.mkdir(destdir, "-p")
for _,file in ipairs(lic.files) do
local cache_flags = {}
- local server = lic.server
- rc, re = cache.fetch_file(info.cache, server, file,
- destdir, nil, cache_flags)
+ if file.sha1 then
+ rc, re = e2tool.verify_hash(info, file.server,
+ file.location, file.sha1)
+ if not rc then
+ return false, e:cat(re)
+ end
+ end
+ rc, re = cache.fetch_file(info.cache, file.server,
+ file.location, destdir, nil,
+ cache_flags)
if not rc then
return false, e:cat(re)
end
end
local hc = hash.hash_start()
hc:hash_line(licence) -- licence name
- hc:hash_line(lic.server) -- server name
- for _,file in ipairs(lic.files) do
- local h, re = e2tool.hash_file(info, lic.server, file)
- if not h then
- return nil, e:cat(re)
- end
- hc:hash_line(file) -- licence file name
- hc:hash_line(h) -- licence file content
+ for _,f in ipairs(lic.files) do
+ hc:hash_line(f.server)
+ hc:hash_line(f.location)
+ if f.sha1 then
+ hc:hash_line(f.sha1)
+ else
+ local h, re = e2tool.hash_file(info, f.server,
+ f.location)
+ if not h then
+ return false, e:cat(re)
+ end
+ hc:hash_line(h)
+ end
end
lic.licenceid, re = hc:hash_finish()
if not lic.licenceid then
elseif not type(lic.files) == "table" then
e:append("files attribute is not a table")
else
- for _,file in ipairs(lic.files) do
- if not type(file) == "string" then
- e:append("file list holds non-string element")
+ for _,f in ipairs(lic.files) do
+ local inherit = {
+ server = lic.server,
+ }
+ local keys = {
+ server = {
+ mandatory = true,
+ type = "string",
+ inherit = true,
+ },
+ location = {
+ mandatory = true,
+ type = "string",
+ inherit = false,
+ },
+ sha1 = {
+ mandatory = false,
+ type = "string",
+ inherit = false,
+ },
+ }
+ local rc, re = check_tab(f, keys, inherit)
+ if not rc then
+ e:cat(re)
+ elseif f.server ~= info.root_server_name and
+ not f.sha1 then
+ e:append("file entry for remote file without"..
+ " `sha1` attribute")
end
end
end
s2 = " "
end
p2(s1, s2, l)
- p3(s1, s2, "server", lic.server)
- for _,file in ipairs(lic.files) do
- p3(s1, s2, "file", file)
+ for _,f in ipairs(lic.files) do
+ p3(s1, s2, "file", string.format("%s:%s", f.server, f.location))
end
end