From 921c210d7f5efd7c2827e0bf3cf87f5f017e5e19 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 13 Nov 2015 18:09:29 +0100 Subject: [PATCH] project: move projid() to sensible location Signed-off-by: Tobias Ulmer --- local/e2tool.lua | 61 -------------------------------------------- local/project.lua | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 61 deletions(-) diff --git a/local/e2tool.lua b/local/e2tool.lua index 96a4c5e..476bd17 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -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 diff --git a/local/project.lua b/local/project.lua index 79f58c7..419f80d 100644 --- a/local/project.lua +++ b/local/project.lua @@ -19,13 +19,16 @@ -- 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: -- 2.39.5