From 8ce0f82f47ba4a6bcce34bd31bc7846d48e15cf0 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Wed, 28 Oct 2009 16:40:49 +0100 Subject: [PATCH] licence config: Switch to new file format, similar to source file configuration, require sha1 checksums to be configured for files located on servers other than "." Signed-off-by: Gordon Hecker --- doc/manual/licences.text | 10 ++++++-- local/e2build.lua | 13 +++++++--- local/e2tool.lua | 52 +++++++++++++++++++++++++++++++--------- local/ls-project.lua | 5 ++-- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/doc/manual/licences.text b/doc/manual/licences.text index 2fa1046..1fc663b 100644 --- a/doc/manual/licences.text +++ b/doc/manual/licences.text @@ -17,9 +17,15 @@ Example: 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", + }, } } } diff --git a/local/e2build.lua b/local/e2build.lua index fd68a43..4929980 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -1067,9 +1067,16 @@ function e2build.collect_project(info, r, return_flags) 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 diff --git a/local/e2tool.lua b/local/e2tool.lua index cc3edde..f1fbc56 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -1341,14 +1341,19 @@ function e2tool.licenceid(info, licence) 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 @@ -1667,9 +1672,34 @@ function e2tool.check_licence(info, l) 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 diff --git a/local/ls-project.lua b/local/ls-project.lua index c9151f6..c2f8a27 100755 --- a/local/ls-project.lua +++ b/local/ls-project.lua @@ -270,9 +270,8 @@ for _,l in pairs(info.licences_sorted) do 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 -- 2.39.5