-- @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
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
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
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
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()
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
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