diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-05-14 22:59:50 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-05-14 22:59:50 +0200 |
commit | de2ebfd1e897e9bea9aee9ecffe1f146dd457adf (patch) | |
tree | 7e8b3037a345152ce93308d6c6419b03b5b1388d | |
parent | 12547b5d6f57b0c8032b1029ed90352f5ac39bdb (diff) | |
download | luaotfload-de2ebfd1e897e9bea9aee9ecffe1f146dd457adf.tar.gz |
[conf,db,diagnose] reimplement runtime cache path handling as configuration task
-rw-r--r-- | src/luaotfload-configuration.lua | 53 | ||||
-rw-r--r-- | src/luaotfload-database.lua | 40 | ||||
-rw-r--r-- | src/luaotfload-diagnostics.lua | 32 |
3 files changed, 82 insertions, 43 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index 535db30..c806915 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -54,6 +54,8 @@ local lfsisdir = lfs.isdir local file = file local filejoin = file.join +local filereplacesuffix = file.replacesuffix + local parsers = luaotfload.parsers @@ -61,6 +63,9 @@ local log = luaotfload.log local logreport = log.report local config_parser = parsers.config +local stripslashes = parsers.stripslashes + +local getwritablepath = caches.getwritablepath ------------------------------------------------------------------------------- --- SETTINGS @@ -106,10 +111,14 @@ local default_config = { termwidth = nil, }, paths = { - names_dir = "names", - cache_dir = "fonts", - index_file = "luaotfload-names.lua", - lookups_file = "luaotfload-lookup-cache.lua", + names_dir = "names", + cache_dir = "fonts", + index_file = "luaotfload-names.lua", + lookups_file = "luaotfload-lookup-cache.lua", + lookup_path_lua = nil, + lookup_path_luc = nil, + index_path_lua = nil, + index_path_luc = nil, }, } @@ -182,8 +191,32 @@ local set_loglevel = function () return true end +local build_cache_paths = function () + local paths = config.luaotfload.paths + local prefix = getwritablepath (paths.names_dir, "") + + if not prefix then + luaotfload.error ("Impossible to find a suitable writeable cache...") + return false + end + + prefix = lpegmatch (stripslashes, prefix) + logreport ("log", 0, "conf", "Root cache directory is %s.", prefix) + + local index_file = filejoin (prefix, paths.index_file) + local lookups_file = filejoin (prefix, paths.lookups_file) + + paths.prefix = prefix + paths.index_path_lua = filereplacesuffix (index_file, "lua") + paths.index_path_luc = filereplacesuffix (index_file, "luc") + paths.lookup_path_lua = filereplacesuffix (lookups_file, "lua") + paths.lookup_path_luc = filereplacesuffix (lookups_file, "luc") + return true +end + reconf_tasks = { { "Set the log level" , set_loglevel }, + { "Build cache paths" , build_cache_paths }, { "Check terminal dimensions" , check_termwidth }, { "Set the font filter" , set_font_filter }, { "Install font name resolver", set_name_resolver }, @@ -263,10 +296,14 @@ local option_spec = { }, }, paths = { - names_dir = { in_t = string_t, }, - cache_dir = { in_t = string_t, }, - index_file = { in_t = string_t, }, - lookups_file = { in_t = string_t, }, + names_dir = { in_t = string_t, }, + cache_dir = { in_t = string_t, }, + index_file = { in_t = string_t, }, + lookups_file = { in_t = string_t, }, + lookup_path_lua = { in_t = string_t, }, + lookup_path_luc = { in_t = string_t, }, + index_path_lua = { in_t = string_t, }, + index_path_luc = { in_t = string_t, }, }, } diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 4fbf797..d903941 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -119,7 +119,6 @@ local tablefastcopy = table.fastcopy local tabletofile = table.tofile local tabletohash = table.tohash local tableserialize = table.serialize -local runasscript = caches == nil --- the font loader namespace is “fonts”, same as in Context --- we need to put some fallbacks into place for when running --- as a script @@ -171,25 +170,24 @@ end --- XXX this belongs into the initialization file! local initialize_env = function () - if not runasscript then - local paths = config.luaotfload.paths - local prefix = getwritablepath (paths.names_dir, "") - if not prefix then - luaotfload.error - ("Impossible to find a suitable writeable cache...") - else - prefix = lpegmatch (stripslashes, prefix) - report ("log", 0, "db", - "Root cache directory is %s.", prefix) - end - - local lookup_path = names.path.lookups - local index = names.path.index - local lookups_file = filejoin (prefix, paths.lookups_file) - local index_file = filejoin (prefix, paths.index_file) - lookup_path.lua, lookup_path.luc = make_luanames (lookups_file) - index.lua, index.luc = make_luanames (index_file) - else --- running as script, inject some dummies + local paths = config.luaotfload.paths + local prefix = getwritablepath (paths.names_dir, "") + if not prefix then + luaotfload.error + ("Impossible to find a suitable writeable cache...") + else + prefix = lpegmatch (stripslashes, prefix) + report ("log", 0, "db", + "Root cache directory is %s.", prefix) + end + + local lookup_path = names.path.lookups + local index = names.path.index + local lookups_file = filejoin (prefix, paths.lookups_file) + local index_file = filejoin (prefix, paths.index_file) + lookup_path.lua, lookup_path.luc = make_luanames (lookups_file) + index.lua, index.luc = make_luanames (index_file) + if not caches then caches = { } local dummy_function = function () end log = { report = dummy_function, @@ -3252,7 +3250,7 @@ end --- unit -> bool save_lookups = function ( ) - local path = names.path.lookups + local path = names.path.lookups local luaname, lucname = path.lua, path.luc if fileiswritable (luaname) and fileiswritable (lucname) then tabletofile (luaname, lookup_cache, true) diff --git a/src/luaotfload-diagnostics.lua b/src/luaotfload-diagnostics.lua index 67119de..1293122 100644 --- a/src/luaotfload-diagnostics.lua +++ b/src/luaotfload-diagnostics.lua @@ -9,8 +9,6 @@ ----------------------------------------------------------------------- -- local names = fonts.names -local luatexstatus = status -local status = config.luaotfload.status local kpse = require "kpse" local kpseexpand_path = kpse.expand_path @@ -99,8 +97,9 @@ local check_index = function (errcnt) return errcnt end -local verify_files = function (errcnt, status) +local verify_files = function (errcnt) out "================ verify files =================" + local status = config.luaotfload.status local hashes = status.hashes local notes = status.notes if not hashes or #hashes == 0 then @@ -243,17 +242,23 @@ end local path = names.path -local desired_permissions = { - { "d", {"r","w"}, function () return caches.getwritablepath () end }, - { "d", {"r","w"}, path.globals.prefix }, - { "f", {"r","w"}, path.index.lua .. ".gz" }, - { "f", {"r","w"}, path.index.luc }, - { "f", {"r","w"}, path.lookups.lua }, - { "f", {"r","w"}, path.lookups.luc }, -} +local desired_permissions +local init_desired_permissions = function () + inspect(config.luaotfload.paths) + local paths = config.luaotfload.paths + desired_permissions = { + { "d", {"r","w"}, function () return caches.getwritablepath () end }, + { "d", {"r","w"}, paths.prefix }, + { "f", {"r","w"}, paths.index_path_lua .. ".gz" }, + { "f", {"r","w"}, paths.index_path_luc }, + { "f", {"r","w"}, paths.lookup_path_lua }, + { "f", {"r","w"}, paths.lookup_path_luc }, + } +end local check_permissions = function (errcnt) out [[=============== file permissions ==============]] + if not desired_permissions then init_desired_permissions () end for i = 1, #desired_permissions do local t, spec, path = unpack (desired_permissions[i]) if type (path) == "function" then @@ -337,8 +342,7 @@ else end out ("Requesting <%s>.", request) - local response, code, headers, status - = https.request (request) + local response, code, headers, status = https.request (request) if status ~= alright then out "Request failed!" return false @@ -629,7 +633,7 @@ local diagnose = function (job) end if asked.files == true then - errcnt = verify_files (errcnt, status) + errcnt = verify_files (errcnt) asked.files = nil end |