From 05e014ba69d57c18c460e0d0e12a7802d9c58225 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 26 Apr 2013 18:21:06 +0200 Subject: add ``flush-cache`` option to fontdbutil --- fontdbutil.lua | 21 +++++++++++++++++++-- luaotfload-database.lua | 33 +++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/fontdbutil.lua b/fontdbutil.lua index 3c60eec..1aa99d0 100755 --- a/fontdbutil.lua +++ b/fontdbutil.lua @@ -126,6 +126,7 @@ This tool is part of the luaotfload package. Valid options are: -u --update update the database -f --force force re-indexing all fonts + -c --flush-cache empty cache of font requests --find="font name" query the database for a font name -F --fuzzy look for approximate matches if --find fails @@ -214,7 +215,7 @@ set. --]]-- local action_sequence = { - "loglevel", "help", "version", "generate", "query" + "loglevel", "help", "version", "flush", "generate", "query" } local action_pending = table.tohash(action_sequence, false) @@ -252,6 +253,19 @@ actions.generate = function (job) return false, false end +actions.flush = function (job) + local success, fontnames = names.flush_cache() + if success then + local savedname = names.save(fontnames) + logs.names_report("info", 2, "cache", + "Cache emptied", #fontnames.mappings) + if savedname then + return true, true + end + end + return false, false +end + actions.query = function (job) local query = job.query @@ -304,6 +318,7 @@ local process_cmdline = function ( ) -- unit -> jobspec local long_options = { alias = 1, + ["flush-cache"] = "c", find = 1, force = "f", fuzzy = "F", @@ -317,7 +332,7 @@ local process_cmdline = function ( ) -- unit -> jobspec version = "V", } - local short_options = "fFiquvVh" + local short_options = "cfFiquvVh" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -366,6 +381,8 @@ local process_cmdline = function ( ) -- unit -> jobspec result.show_info = true elseif v == "alias" then config.luaotfload.self = optarg[n] + elseif v == "c" then + action_pending["flush"] = true end end diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 0c47bfd..7c6e657 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -69,7 +69,7 @@ fonts.definers = fonts.definers or { } local names = fonts.names -names.version = 2.201 +names.version = 2.202 names.data = nil names.path = { basename = "luaotfload-names.lua", @@ -231,6 +231,7 @@ end --- define locals in scope local find_closest +local flush_cache local font_fullinfo local load_names local read_fonts_conf @@ -367,9 +368,10 @@ TODO: × 3) make caching optional (via the config table) for debugging × 4) make names_update() cache aware (nil if “force”) × 5) add logging - 6) add cache control to fontdbutil - 7) incr db version - 8) ??? + × 6) add cache control to fontdbutil + × 7) incr db version + 8) wishlist: save cache only at the end of a run + 9) ??? n) PROFIT!!! --doc]]-- @@ -508,12 +510,7 @@ font database created by the mkluatexfontdb script. --- resolve = function (_,_,specification) -- the 1st two parameters are used by ConTeXt - if not fonts_loaded then - print("=============") - print(names.data) - names.data = load_names() - --os.exit() - end + if not fonts_loaded then names.data = load_names() end local data = names.data if specification.lookup == "file" then @@ -1291,6 +1288,13 @@ local function scan_os_fonts(fontnames, newfontnames) return n_scanned, n_new end +flush_cache = function (fontnames) + if not fontnames then fontnames = load_names() end + fontnames.request_cache = { } + collectgarbage"collect" + return true, fontnames +end + --- dbobj -> bool -> dbobj update_names = function (fontnames, force) local starttime = os.gettimeofday() @@ -1376,10 +1380,11 @@ scan_external_dir = function (dir) end --- export functionality to the namespace “fonts.names” -names.scan = scan_external_dir -names.load = load_names -names.update = update_names -names.save = save_names +names.flush_cache = flush_cache +names.load = load_names +names.save = save_names +names.scan = scan_external_dir +names.update = update_names names.resolve = resolve --- replace the resolver from luatex-fonts names.resolvespec = resolve -- cgit v1.2.3