]> git.e2factory.org Git - e2factory.git/commitdiff
cache: move e2lib.setup_cache into cache module
authorTobias Ulmer <tu@emlix.com>
Wed, 7 Sep 2016 15:28:44 +0000 (17:28 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:18 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/cache.lua
generic/e2lib.lua
global/e2-create-project.lua
global/e2-fetch-project.lua
global/e2-install-e2.lua
local/e2tool.lua

index 7899657d221587e29e61d029bd579da1c449c7de..170d9ca2375348248fdc1f08e853f6948b15fe6b 100644 (file)
@@ -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
index ad2c29bd0a5e2975a22a8e4eda646ff78377de93..b3474593c2d8e360ba09e122d743f3355ae3bc2b 100644 (file)
@@ -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
index a0e9f861a62a3dc425ce63aee06b3705ee141bf8..1f7f6df46511a2e464ca5f208c4aa12c4184f64a 100644 (file)
@@ -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
index 92a3899f74e3ed0def40d741e2721dc6859950ff..54596aa695c92ea0120458b62e15f7a85076fa58 100644 (file)
@@ -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
index 418d509874332df59f387f35df19783d56ba893c..932766666d4e642601419e319d0aa1970d462ad7 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+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
index da75f13dc08059f8dde6efb22021f8abd4a48497..0b77c9bc3a664c31e6d46d694bef94bef01dfb9d 100644 (file)
@@ -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