]> git.e2factory.org Git - e2factory.git/commitdiff
project: move projid() to sensible location
authorTobias Ulmer <tu@emlix.com>
Fri, 13 Nov 2015 17:09:29 +0000 (18:09 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:18 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/e2tool.lua
local/project.lua

index 96a4c5e3a8a0c4a9ac3dc5232e88f514c7d12165..476bd177696fa2d083a5aa4d581b9aa0a42689f4 100644 (file)
@@ -1284,67 +1284,6 @@ function e2tool.verify_hash(info, server, location, sha1)
     return true
 end
 
---- Cache for projid() result.
-local projid_cache = false
-
---- Calculate the Project ID. The Project ID consists of files in proj/init
--- as well as some keys from proj/config and buildconfig. Returns a cached
--- value after the first call.
--- @return Project ID or false on error.
--- @return Error object on failure
-local function projid(info)
-    local rc, re, hc, cs
-
-    if projid_cache then
-        return projid_cache
-    end
-
-    -- catch proj/init/*
-    hc, re = hash.hash_start()
-    if not hc then return false, re end
-
-    for f, re in e2lib.directory(e2lib.join(info.root, "proj/init")) do
-        if not f then
-            return false, re
-        end
-
-        local location, file, fileid
-        if not e2lib.is_backup_file(f) then
-            location = e2lib.join("proj/init", f)
-            file = {
-                server = info.root_server_name,
-                location = location,
-            }
-
-            fileid, re = e2tool.fileid(info, file)
-            if not fileid then
-                return false, re
-            end
-
-            rc, re = hash.hash_line(hc, location)   -- the filename
-            if not rc then return false, re end
-
-            rc, re = hash.hash_line(hc, fileid)     -- the file content cs
-            if not rc then return false, re end
-        end
-    end
-    rc, re = hash.hash_line(hc, project.release_id())
-    if not rc then return false, re end
-    rc, re = hash.hash_line(hc, project.name())
-    if not rc then return false, re end
-    rc, re = hash.hash_line(hc, project.chroot_arch())
-    if not rc then return false, re end
-    rc, re = hash.hash_line(hc, buildconfig.VERSION)
-    if not rc then return false, re end
-
-    cs, re = hash.hash_finish(hc)
-    if not cs then return false, re end
-
-    projid_cache = cs
-
-    return cs
-end
-
 --- verify that remote files match the checksum. The check is skipped when
 -- check-remote is not enabled or cache is not enabled.
 -- @param info
index 79f58c7577f06d5beb316636545352ac870bb206..419f80d1e5972b4caed5f45672d0bc40811972d6 100644 (file)
 -- more details.
 
 local project = {}
+local buildconfig = require("buildconfig")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local err = require("err")
+local hash = require("hash")
 local strict = require("strict")
 
 local _prj = {}
 local _config_loaders = {}
+local _projid_cache = false
 
 --- Check and load e2project callback function signature.
 -- @function load_project_config_cb
@@ -187,6 +190,21 @@ function project.deploy_results_iter()
     end
 end
 
+--- Return true if resultname is the list of deploy_results.
+-- @param resultname Result name.
+-- @return True if result name was found, false otherwise.
+function project.deploy_results_lookup(resultname)
+    assert(type(_prj.deploy_results) == "table")
+    assert(type(resultname) == "string")
+
+    for _,r in ipairs(_prj.deploy_results) do
+        if resultname == r then
+            return true
+        end
+    end
+    return false
+end
+
 --- Iterator that returns the default results as string.
 -- @return Iterator function.
 function project.default_results_iter()
@@ -199,6 +217,53 @@ function project.default_results_iter()
     end
 end
 
+--- Calculate the Project ID. The Project ID consists of files in proj/init
+-- as well as some keys from proj/config and buildconfig. Returns a cached
+-- value after the first call.
+-- @return Project ID or false on error.
+-- @return Error object on failure
+function project.projid(info)
+    local re, hc, cs
+
+    if _projid_cache then
+        return _projid_cache
+    end
+
+    -- catch proj/init/*
+    hc = hash.hash_start()
+
+    for f, re in e2lib.directory(e2lib.join(info.root, "proj/init")) do
+        if not f then
+            return false, re
+        end
+
+        local location, file, fileid
+        if not e2lib.is_backup_file(f) then
+            location = e2lib.join("proj/init", f)
+            file = {
+                server = info.root_server_name,
+                location = location,
+            }
+
+            fileid, re = e2tool.fileid(info, file)
+            if not fileid then
+                return false, re
+            end
+
+            hash.hash_line(hc, location)   -- the filename
+            hash.hash_line(hc, fileid)     -- the file content cs
+        end
+    end
+    hash.hash_line(hc, project.release_id())
+    hash.hash_line(hc, project.name())
+    hash.hash_line(hc, project.chroot_arch())
+    hash.hash_line(hc, buildconfig.VERSION)
+
+    _projid_cache = hash.hash_finish(hc)
+
+    return _projid_cache
+end
+
 return strict.lock(project)
 
 -- vim:sw=4:sts=4:et: