]> git.e2factory.org Git - e2factory.git/commitdiff
buildid: refactor file id calculation
authorGordon Hecker <gh@emlix.com>
Thu, 29 Oct 2009 15:36:42 +0000 (16:36 +0100)
committerGordon Hecker <gh@emlix.com>
Mon, 2 Nov 2009 12:44:22 +0000 (13:44 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
local/e2tool.lua
local/files.lua

index f1fbc566f84aabfad6fe89ddd8c60647d1336fee..d10df267878aec23ddf1165f7bf04e1d3ad6c5c0 100644 (file)
@@ -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))
index 63e9bc67b9401b887ab1764d8c75a0c9b4f1a992..4ced4c69d89446361efa08e6a12a39f6f2aeb489 100644 (file)
@@ -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)