From e297bab475a4467ecdf50342dbd1dac7f6487278 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Thu, 29 Oct 2009 16:36:42 +0100 Subject: [PATCH] buildid: refactor file id calculation Signed-off-by: Gordon Hecker --- local/e2tool.lua | 47 +++++++++++++++++++++++++++++------------------ local/files.lua | 13 ++++--------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/local/e2tool.lua b/local/e2tool.lua index f1fbc56..d10df26 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -1326,6 +1326,27 @@ function e2tool.calc_sourceids(info, sourceset) return true, nil end +--- calculate a representation for file content. The name and location +-- attributes are not included. +-- @param file table: file table from configuration +-- @return fileid string: hash value, or nil +-- @return an error object on failure +function e2tool.fileid(info, file) + local fileid + local re + local e = new_error("error calculating file id for file %s:%s", + file.server, file.location) + if file.sha1 then + fileid = file.sha1 + else + fileid, re = e2tool.hash_file(info, file.server, file.location) + if not fileid then + return nil, e:cat(re) + end + end + return fileid +end + --- calculate licence id -- @param info -- @param licence @@ -1344,16 +1365,11 @@ function e2tool.licenceid(info, licence) 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) + local fileid = e2tool.fileid(info, f) + if not fileid then + return false, e:cat(re) end + hc:hash_line(fileid) end lic.licenceid, re = hc:hash_finish() if not lic.licenceid then @@ -1539,16 +1555,11 @@ function e2tool.chrootgroupid(info, groupname) for _,f in ipairs(g.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) + local fileid = e2tool.fileid(info, f) + if not fileid then + return false, e:cat(re) end + hc:hash_line(fileid) end e2lib.log(4, string.format("hash data for chroot group %s\n%s", groupname, hc.data)) diff --git a/local/files.lua b/local/files.lua index 63e9bc6..4ced4c6 100644 --- a/local/files.lua +++ b/local/files.lua @@ -375,16 +375,11 @@ function files.sourceid(info, sourcename, sourceset) hash.hash_line(hc, licenceid) end for _,f in ipairs(src.file) do - if f.sha1 then - hash.hash_line(hc, f.sha1) - else - local h, re = e2tool.hash_file(info, f.server, - f.location) - if not h then - return false, e:cat(re) - end - hash.hash_line(hc, h) + local fileid = e2tool.fileid(info, f) + if not fileid then + return false, e:cat(re) end + hash.hash_line(hc, fileid) hash.hash_line(hc, f.checksum_file) hash.hash_line(hc, f.location) hash.hash_line(hc, f.server) -- 2.39.5