From: Gordon Hecker Date: Thu, 14 Jan 2010 14:26:52 +0000 (+0100) Subject: cache: cleanup: move server and cache related code from e2tool module to e2lib and... X-Git-Tag: e2factory-2.3.4pre1~53 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=a1936fe24ddb4dcc99d883b1ce16318248873159;p=e2factory.git cache: cleanup: move server and cache related code from e2tool module to e2lib and cache modules Signed-off-by: Gordon Hecker --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index c55bb17..3e0e032 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1885,31 +1885,36 @@ function e2lib.parse_server_location(arg, default_server) return nil, "can't parse location" end ---- setup a cache --- @param name string: cache name --- @param cache_url string: where to place the cache? --- @param servers table: server configuration table +--- setup cache from the global server configuration -- @return a cache object -- @return an error object on failure -function e2lib.setup_cache(name, cache_url, servers) +function e2lib.setup_cache() local e = new_error("setting up cache failed") - local cache, re = cache.new_cache(name, cache_url) - if not cache then + local config = e2lib.get_global_config() + if type(config.cache) ~= "table" or type(config.cache.path) ~= "string" then + return false, e:append("invalid cache configuration: config.cache.path") + end + -- replace %u by the username, %l by the project location + local replace = { u=e2lib.username } + 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(servers) do + 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 = new_cache_entry(cache, name, server.url, flags) + local rc, re = cache.new_cache_entry(c, name, server.url, flags) if not rc then return nil, e:cat(re) end end - return cache, nil + return c, nil end --- replace format elements, according to the table diff --git a/local/e2tool.lua b/local/e2tool.lua index 6246393..2e02621 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -555,46 +555,6 @@ The newest configuration syntax supported by the tools is %s. info.name = info.project.name info.default_results = info.project.default_results - local function add_builtin_servers(info) - local function add_server(info, name, url, cachable) - e2lib.warnf("WDEFAULT", "setting up builtin server:") - e2lib.warnf("WDEFAULT", " %s [%s]", name, url) - local s = {} - s.name = name - s.url = url - s.cachable = cachable - if info.servers[name] then - return false, new_error( - "cannot setup builtin server %s: server exists", name) - end - info.servers[name] = s - return true, nil - end - local rc, re - rc, re = add_server(info, info.root_server_name, info.root_server, false) - if not rc then - return false, re - end - info.servers[info.root_server_name].writeback = true - if not info.servers[info.default_repo_server] then - e2lib.warnf("WPOLICY", "server %s is unconfigured.", - info.default_repo_server) - e2lib.warnf("WPOLICY", "Cannot setup server %s", - info.proj_storage_server_name) - -- do not treat that as an error, unless the server is used. - return true, nil - end - -- create the new url - local proj_storage_server = string.format("%s/%s", - info.servers[info.default_repo_server].url, info.project_location) - rc, re = add_server(info, info.proj_storage_server_name, - proj_storage_server, true) - if not rc then - return false, re - end - return true, nil - end - -- chroot config info.chroot_config_file = "proj/chroot" rc, re = e2tool.read_chroot_config(info) @@ -643,11 +603,6 @@ The newest configuration syntax supported by the tools is %s. end end - -- servers - info.server_default_config = { -- default values - cachable = true, - } - -- read .e2/proj-location info.project_location_config = string.format("%s/.e2/project-location", info.root) @@ -662,30 +617,6 @@ The newest configuration syntax supported by the tools is %s. end info.project_location = l e2lib.log(4, string.format("project location is %s", info.project_location)) - local config = e2lib.get_global_config() - info.servers = config.servers - if not info.servers then - return false, e:append("no servers configured in global configuration") - end - local rc, re = add_builtin_servers(info) - if not rc then - return false, e:cat(re) - end - info.servers[".fix"] = nil - for name, server in pairs(info.servers) do - server.name = name - -- apply default values - for k, v in pairs(info.server_default_config) do - if server[k] == nil then - server[k] = info.server_default_config[k] - end - end - -- print for debugging purposes - for k, v in pairs(server) do - v = tostring(v) - e2lib.log(4, string.format("%-20s: %-10s %s", name, k, v)) - end - end -- warn if deprecated config files still exist local deprecated_files = { @@ -702,20 +633,14 @@ The newest configuration syntax supported by the tools is %s. end end - local cache_url - if config.cache and config.cache.path then - -- replace %u by the username, %l by the project location - local replace = { u=e2lib.username, l=info.project_location } - local cache_path = e2lib.format_replace(config.cache.path, replace) - cache_url = string.format("file://%s", cache_path) - else - cache_url = string.format("%s/cache", info.root_server) - e2lib.warnf("WPOLICY", "cache defaulting to %s", cache_url) - end - info.cache, re = e2lib.setup_cache("local cache", cache_url, info.servers) + info.cache, re = e2lib.setup_cache() if not info.cache then return false, e:cat(re) end + rc = info.cache:new_cache_entry(info.root_server_name, + info.root_server, { writeback=true }, nil, nil ) + rc = info.cache:new_cache_entry(info.proj_storage_server_name, + nil, nil, info.default_repo_server, info.project_location) --e2tool.add_source_results(info) @@ -733,13 +658,6 @@ The newest configuration syntax supported by the tools is %s. end table.sort(info.sources_sorted) - -- provide sorted list of servers - info.servers_sorted = {} - for s, srv in pairs(info.servers) do - table.insert(info.servers_sorted, s) - end - table.sort(info.servers_sorted) - rc, re = policy.init(info) if not rc then return false, e:cat(re) @@ -2522,7 +2440,7 @@ function e2tool.check_chroot_config(info) if not grp.server then e:append("in group: %s", grp.name) e:append(" `server' attribute missing") - elseif not info.servers[grp.server] then + elseif not info.cache:valid_server(grp.server) then e:append("in group: %s", grp.name) e:append(" no such server: %s", grp.server) end diff --git a/local/files.lua b/local/files.lua index 2f170c4..9f29a74 100644 --- a/local/files.lua +++ b/local/files.lua @@ -76,7 +76,7 @@ function files.validate_source(info, sourcename) if not f.server then e:append("source has file entry without `server' attribute") end - if f.server and (not info.servers[f.server]) then + if f.server and (not info.cache:valid_server(f.server)) then e:append("invalid server: %s", f.server) end if not f.location then diff --git a/local/git.lua b/local/git.lua index d518857..2af4086 100644 --- a/local/git.lua +++ b/local/git.lua @@ -269,7 +269,7 @@ function git.validate_source(info, sourcename) if not src.server then e:append("source has no `server' attribute") end - if src.server and (not info.servers[src.server]) then + if src.server and (not info.cache:valid_server(src.server)) then e:append("invalid server: %s", src.server) end if not src.licences then diff --git a/local/ls-project.lua b/local/ls-project.lua index c2f8a27..5baf3cc 100755 --- a/local/ls-project.lua +++ b/local/ls-project.lua @@ -188,9 +188,10 @@ p0(s1, s2, info.name) local s1 = "|" local s2 = "|" p1(s1, s2, "servers") -local len = #info.servers_sorted -for _,s in ipairs(info.servers_sorted) do - local srv = info.servers[s] +local servers_sorted = info.cache:servers() +local len = #servers_sorted +for _,s in ipairs(servers_sorted) do + local ce = info.cache:ce_by_server(s) len = len - 1 if len > 0 then s2 = "|" @@ -198,10 +199,14 @@ for _,s in ipairs(info.servers_sorted) do s2 = " " end p2(s1, s2, s) - for k,v in pairs(srv) do - if k ~= "name" then - p3(s1, s2, k, tostring(v)) - end + p3(s1, s2, "url", ce.remote_url) + local flags = {} + for k,v in pairs(ce.flags) do + table.insert(flags, k) + end + table.sort(flags) + for _,k in ipairs(flags) do + p3(s1, s2, k, tostring(ce.flags[k])) end end print(" |")