From: Tobias Ulmer Date: Wed, 7 Sep 2016 15:28:44 +0000 (+0200) Subject: cache: move e2lib.setup_cache into cache module X-Git-Tag: e2factory-2.3.15rc1~104 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=6c4e379c2465533865746f445e5ebde6a8943a41;p=e2factory.git cache: move e2lib.setup_cache into cache module Signed-off-by: Tobias Ulmer --- diff --git a/generic/cache.lua b/generic/cache.lua index 7899657..170d9ca 100644 --- a/generic/cache.lua +++ b/generic/cache.lua @@ -56,6 +56,41 @@ local url = require("url") -- @name flags -- @field cachable treat a server as cachable? +--- Setup cache from the global server configuration +-- @param config global config table +-- @return a cache object +-- @return an error object on failure +function cache.setup_cache(config) + assertIsTable(config) + + local e = err.new("setting up cache failed") + + if type(config.cache) ~= "table" or type(config.cache.path) ~= "string" then + return false, e:append("invalid cache configuration: config.cache.path") + end + + local replace = { u = e2lib.globals.osenv["USER"] } + local cache_path = e2lib.format_replace(config.cache.path, replace) + local cache_url = string.format("file://%s", cache_path) + local c, re = cache.new_cache("local cache", cache_url) + if not c then + return nil, e:cat(re) + end + for name,server in pairs(config.servers) do + local flags = {} + flags.cachable = server.cachable + flags.cache = server.cache + flags.islocal = server.islocal + flags.writeback = server.writeback + flags.push_permissions = server.push_permissions + local rc, re = cache.new_cache_entry(c, name, server.url, flags) + if not rc then + return nil, e:cat(re) + end + end + return c, nil +end + --- Create a new cache. -- @param name Cache name. -- @param url base url for this cache, must use file transport diff --git a/generic/e2lib.lua b/generic/e2lib.lua index ad2c29b..b347459 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -2333,43 +2333,6 @@ function e2lib.parse_server_location(serverloc, default_server) return strict.lock(sl) end ---- setup cache from the global server configuration --- @return a cache object --- @return an error object on failure -function e2lib.setup_cache() - local e = err.new("setting up cache failed") - - local config, re = e2lib.get_global_config() - if not config then - return false, re - end - - if type(config.cache) ~= "table" or type(config.cache.path) ~= "string" then - return false, e:append("invalid cache configuration: config.cache.path") - end - - local replace = { u = e2lib.globals.osenv["USER"] } - local cache_path = e2lib.format_replace(config.cache.path, replace) - local cache_url = string.format("file://%s", cache_path) - local c, re = cache.new_cache("local cache", cache_url) - if not c then - return nil, e:cat(re) - end - for name,server in pairs(config.servers) do - local flags = {} - flags.cachable = server.cachable - flags.cache = server.cache - flags.islocal = server.islocal - flags.writeback = server.writeback - flags.push_permissions = server.push_permissions - local rc, re = cache.new_cache_entry(c, name, server.url, flags) - if not rc then - return nil, e:cat(re) - end - end - return c, nil -end - --- replace format elements, according to the table -- @param s string: the string to work on -- @param t table: a table of key-value pairs diff --git a/global/e2-create-project.lua b/global/e2-create-project.lua index a0e9f86..1f7f6df 100644 --- a/global/e2-create-project.lua +++ b/global/e2-create-project.lua @@ -126,7 +126,7 @@ local function e2_create_project(arg) error(e:cat(re)) end - local scache, re = e2lib.setup_cache() + local scache, re = cache.setup_cache(config) if not scache then error(e:cat(re)) end diff --git a/global/e2-fetch-project.lua b/global/e2-fetch-project.lua index 92a3899..54596aa 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -59,8 +59,13 @@ local function e2_fetch_project(arg) error(re) end + local config, re = e2lib.get_global_config() + if not config then + error(e:cat(re)) + end + -- setup cache - local scache, re = e2lib.setup_cache() + local scache, re = cache.setup_cache(config) if not scache then error(e:cat(re)) end diff --git a/global/e2-install-e2.lua b/global/e2-install-e2.lua index 418d509..9327666 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -28,12 +28,13 @@ along with this program. If not, see . ]] +local buildconfig = require("buildconfig") +local cache = require("cache") local e2lib = require("e2lib") local e2option = require("e2option") local eio = require("eio") -local generic_git = require("generic_git") local err = require("err") -local buildconfig = require("buildconfig") +local generic_git = require("generic_git") local function e2_install_e2(arg) local rc, re = e2lib.init() @@ -73,7 +74,7 @@ local function e2_install_e2(arg) error(err.new("no servers configured in global config")) end - local scache, re = e2lib.setup_cache() + local scache, re = cache.setup_cache(config) if not scache then error(e:cat(re)) end diff --git a/local/e2tool.lua b/local/e2tool.lua index da75f13..0b77c9b 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -515,7 +515,12 @@ function e2tool.collect_project_info(info, skip_load_config) e2lib.logf(4, "project location is %s", info.project_location) -- setup cache - info.cache, re = e2lib.setup_cache() + local config, re = e2lib.get_global_config() + if not config then + return false, e:cat(re) + end + + info.cache, re = cache.setup_cache(config) if not info.cache then return false, e:cat(re) end