diff options
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-cache.lua')
-rw-r--r-- | Master/texmf-dist/scripts/context/lua/mtx-cache.lua | 141 |
1 files changed, 82 insertions, 59 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-cache.lua b/Master/texmf-dist/scripts/context/lua/mtx-cache.lua index c2a0db00d89..08202bbf816 100644 --- a/Master/texmf-dist/scripts/context/lua/mtx-cache.lua +++ b/Master/texmf-dist/scripts/context/lua/mtx-cache.lua @@ -6,91 +6,114 @@ if not modules then modules = { } end modules ['mtx-cache'] = { license = "see context related readme files" } -scripts = scripts or { } -scripts.cache = scripts.cache or { } +local helpinfo = [[ +--purge remove not used files +--erase completely remove cache +--list show cache -function scripts.cache.collect_one(...) - local path = caches.setpath(...) - local tmas = dir.glob(path .. "/*.tma") - local tmcs = dir.glob(path .. "/*.tmc") - return path, tmas, tmcs -end +--all all (not yet implemented) +]] -function scripts.cache.collect_two(...) - local path = caches.setpath(...) - local rest = dir.glob(path .. "/**/*") - return path, rest -end +local application = logs.application { + name = "mtx-cache", + banner = "ConTeXt & MetaTeX Cache Management 0.10", + helpinfo = helpinfo, +} -local suffixes = { "afm", "tfm", "def", "enc", "otf", "mp", "data" } +local report = application.report + +scripts = scripts or { } +scripts.cache = scripts.cache or { } -function scripts.cache.process_one(action) - for i=1,#suffixes do - action("fonts", suffixes[i]) +local function collect(path) + local all = dir.glob(path .. "/**/*") + local tmas, tmcs, rest = { }, { }, { } + for i=1,#all do + local name = all[i] + local suffix = file.suffix(name) + if suffix == "tma" then + tmas[#tmas+1] = name + elseif suffix == "tmc" then + tmcs[#tmcs+1] = name + else + rest[#rest+1] = name + end end + return tmas, tmcs, rest, all end -function scripts.cache.process_two(action) - action("curl") +local function list(banner,path,tmas,tmcs,rest) + report("%s: %s",banner,path) + report() + report("tma : %4i",#tmas) + report("tmc : %4i",#tmcs) + report("rest : %4i",#rest) + report("total : %4i",#tmas+#tmcs+#rest) + report() end --- todo: recursive delete of paths - -function scripts.cache.remove(list,keep) - local n, keepsuffixes = 0, table.tohash(keep or { }) +local function purge(banner,path,list,all) + report("%s: %s",banner,path) + report() + local n = 0 for i=1,#list do local filename = list[i] if string.find(filename,"luatex%-cache") then -- safeguard - if not keepsuffixes[file.extname(filename) or ""] then + if all then os.remove(filename) n = n + 1 + else + local suffix = file.suffix(filename) + if suffix == "tma" then + local checkname = file.replacesuffix(filename,"tma","tmc") + if lfs.isfile(checkname) then + os.remove(filename) + n = n + 1 + end + end end end end - return n + report("removed tma files : %i",n) + report() end -function scripts.cache.delete(all,keep) - scripts.cache.process_one(function(...) - local path, rest = scripts.cache.collect_one(...) - local n = scripts.cache.remove(rest,keep) - logs.report("cache path",string.format("%4i files out of %4i deleted on %s",n,#rest,path)) - end) - scripts.cache.process_two(function(...) - local path, rest = scripts.cache.collect_two(...) - local n = scripts.cache.remove(rest,keep) - logs.report("cache path",string.format("%4i files out of %4i deleted on %s",n,#rest,path)) - end) +function scripts.cache.purge() + local writable = caches.getwritablepath() + local tmas, tmcs, rest = collect(writable) + list("writable path",writable,tmas,tmcs,rest) + local n = purge("writable path",writable,tmas) + list("writable path",writable,tmas,tmcs,rest) end -function scripts.cache.list(all) - scripts.cache.process_one(function(...) - local path, tmas, tmcs = scripts.cache.collect_one(...) - logs.report("cache path",string.format("%4i (tma:%4i, tmc:%4i) %s",#tmas+#tmcs,#tmas,#tmcs,path)) - logs.report("cache path",string.format("%4i (tma:%4i, tmc:%4i) %s",#tmas+#tmcs,#tmas,#tmcs,path)) - end) - scripts.cache.process_two(function(...) - local path, rest = scripts.cache.collect_two("curl") - logs.report("cache path",string.format("%4i %s",#rest,path)) - end) +function scripts.cache.erase() + local writable = caches.getwritablepath() + local tmas, tmcs, rest, all = collect(writable) + list("writable path",writable,tmas,tmcs,rest) + local n = purge("writable path",writable,all,true) + list("writable path",writable,tmas,tmcs,rest) end -logs.extendbanner("ConTeXt & MetaTeX Cache Management 0.10") - -messages.help = [[ ---purge remove not used files ---erase completely remove cache ---list show cache - ---all all (not yet implemented) -]] +function scripts.cache.list() + local readables = caches.getreadablepaths() + local writable = caches.getwritablepath() + local tmas, tmcs, rest = collect(writable) + list("writable path",writable,tmas,tmcs,rest) + for i=1,#readables do + local readable = readables[i] + if readable ~= writable then + local tmas, tmcs = collect(readable) + list("readable path",readable,tmas,tmcs,rest) + end + end +end if environment.argument("purge") then - scripts.cache.delete(environment.argument("all"),{"tmc"}) + scripts.cache.purge() elseif environment.argument("erase") then - scripts.cache.delete(environment.argument("all")) + scripts.cache.erase() elseif environment.argument("list") then - scripts.cache.list(environment.argument("all")) + scripts.cache.list() else - logs.help(messages.help) + application.help() end |