]> git.e2factory.org Git - e2factory.git/commitdiff
cache: cleanup: move server and cache related code from e2tool module to e2lib and...
authorGordon Hecker <gh@emlix.com>
Thu, 14 Jan 2010 14:26:52 +0000 (15:26 +0100)
committerGordon Hecker <gh@emlix.com>
Fri, 12 Feb 2010 09:51:58 +0000 (10:51 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
generic/e2lib.lua
local/e2tool.lua
local/files.lua
local/git.lua
local/ls-project.lua

index c55bb17987774cfbb75c631bdf04e4740f30dda3..3e0e032d2cc30ef9be98edca448e35a183e2e9ac 100644 (file)
@@ -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
index 6246393213e327fdad8f3a895404a5925c64de89..2e02621b70460ca553ec167923c6701beeac8feb 100644 (file)
@@ -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
index 2f170c41517cc801f232229ec0e6741c0061decf..9f29a74eccb014cf51844ebc7a287a2eeb71859c 100644 (file)
@@ -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
index d518857572a8d2d4c5d4ff9a62f43f6b899534ab..2af4086d469c7dbb92055a14d88b8f5f7dbe84d4 100644 (file)
@@ -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
index c2f8a276dfa2ae4c5c31d5cf8e992a9985d3d58d..5baf3cc14eccf9105863686ffda28561e2ca3bed 100755 (executable)
@@ -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("   |")