From c917abdd4c6032b1e715555bc626a987b014e4ab Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 6 Jul 2013 01:37:49 +0200 Subject: systemize path handling ; improve cache write errors --- luaotfload-tool.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 4d25d53..d618992 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -93,7 +93,7 @@ local config = config config.luaotfload = config.luaotfload or { } config.luaotfload.names_dir = config.luaotfload.names_dir or "names" config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" -config.luaotfload.names_file = config.luaotfload.names_file +config.luaotfload.index_file = config.luaotfload.index_file or "luaotfload-names.lua" do -- we don’t have file.basename and the likes yet, so inline parser ftw @@ -143,11 +143,9 @@ local names = fonts.names local sanitize_string = names.sanitize_string ---local db_src_out = names.path.dir.."/"..names.path.basename -local names_plain = file.join ( - caches.getwritablepath (config.luaotfload.names_dir), - config.luaotfload.names_file) -local names_bin = file.replacesuffix (names_plain, "luc") +local pathdata = names.path +local names_plain = pathdata.lookups.lua +local names_bin = pathdata.lookups.luc local help_messages = { ["luaotfload-tool"] = [[ -- cgit v1.2.3 From 0df29d1d2f8c6c3a9e11959207912197a43d456f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 6 Jul 2013 02:18:35 +0200 Subject: fix names of bytecode compiled files --- luaotfload-tool.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index d618992..0752cca 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -143,9 +143,9 @@ local names = fonts.names local sanitize_string = names.sanitize_string -local pathdata = names.path -local names_plain = pathdata.lookups.lua -local names_bin = pathdata.lookups.luc +local pathdata = names.path +local names_plain = pathdata.index.lua +local names_bin = pathdata.index.luc local help_messages = { ["luaotfload-tool"] = [[ -- cgit v1.2.3 From 9504cd2bf2c83d1c8b2326967836ad2c9f03178c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 7 Jul 2013 15:46:56 +0200 Subject: add self test (--diagnose) to luaotfload-tool.lua --- luaotfload-tool.lua | 116 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 13 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 0752cca..5a9e08d 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -26,6 +26,8 @@ see the luaotfload documentation for more info. Report bugs to --doc]]-- +kpse.set_program_name "luatex" + --[[doc-- We test for Lua 5.1 by means of capability detection to see if @@ -36,7 +38,15 @@ see the luaotfload documentation for more info. Report bugs to --doc]]-- -kpse.set_program_name "luatex" +local md5sumhexa = md5.sumhexa +local stringexplode = string.explode +local stringformat = string.format +local stringlower = string.lower +local stringrep = string.rep +local tableconcat = table.concat +local texiowrite_nl = texio.write_nl +local texiowrite = texio.write +local kpsefind_file = kpse.find_file local runtime if _G.getfenv ~= nil then -- 5.1 or LJ @@ -44,26 +54,19 @@ if _G.getfenv ~= nil then -- 5.1 or LJ runtime = { "jit", jit.version } else runtime = { "stock", _VERSION } - local oldscript = kpse.find_file "luaotfload-legacy-tool.lua" + local oldscript = kpsefind_file "luaotfload-legacy-tool.lua" return require (oldscript) end else -- 5.2 runtime = { "stock", _VERSION } end -local stringexplode = string.explode -local stringformat = string.format -local stringlower = string.lower -local stringrep = string.rep -local tableconcat = table.concat -local texiowrite_nl = texio.write_nl -local texiowrite = texio.write local C, Ct, P, S = lpeg.C, lpeg.Ct, lpeg.P, lpeg.S local lpegmatch = lpeg.match local loader_file = "luatexbase.loader.lua" -local loader_path = assert(kpse.find_file(loader_file, "lua"), +local loader_path = assert(kpsefind_file(loader_file, "lua"), "File '"..loader_file.."' not found") @@ -121,6 +124,8 @@ config.lualibs.load_extended = false require "lualibs" +local ioloaddata = io.loaddata + --[[doc-- \fileent{luatex-basics-gen.lua} calls functions from the \luafunction{texio.*} library; too much for our taste. @@ -646,8 +651,9 @@ set. --]]-- local action_sequence = { - "loglevel", "help", "version", "blacklist", "cache", - "flush", "generate", "list", "query", + "loglevel", "help", "version", "diagnose", + "blacklist", "cache", "flush", "generate", + "list", "query", } local action_pending = table.tohash(action_sequence, false) @@ -913,6 +919,87 @@ actions.list = function (job) return true, true end +do + local hash_list = "luaotfload-files" + + local out = function (...) + logs.names_report (false, 0, "diagnose", ...) + end + + local verify_files = function (errcnt) + out ("Loading file hashes.") + local hashes = require (hash_list) + if not hashes then + out ("Testing %d files for integrity.", nhashes) + return 1/0 + end + local nhashes = #hashes + out ("Testing %d files for integrity.", nhashes) + for i = 1, nhashes do + local fname, canonicalsum = unpack (hashes[i]) + local location = kpsefind_file (fname) + if not location then + errcnt = errcnt + 1 + out ("FAILED: file %d missing.", fname) + else + out ("File: %s.", location) + local raw = ioloaddata (location) + if not raw then + errcnt = errcnt + 1 + out ("FAILED: file %d not readable.", fname) + else + local sum = md5sumhexa (raw) + if sum ~= canonicalsum then + errcnt = errcnt + 1 + out ("FAILED: checksum mismatch for file %s.", + fname) + out ("Expected %s, got %s.", canonicalsum, sum) + else + out ("Ok, %s passed.", fname) + end + end + end + end + return errcnt + end + + actions.diagnose = function (job) + local errcnt = 0 + errcnt = verify_files (errcnt) + + if errcnt == 0 then --> success + out ("Everything appears to be in order, \z + you may sleep well.") + return true, false + else + out ( [[=============================================== + WARNING + =============================================== + + The diagnostic detected %d errors. + + This version of luaotfload may have been + tampered with. Modified versions of the + luaotfload source are unsupported. Read the log + carefully and get a clean version from CTAN or + github: + + × http://ctan.org/tex-archive/macros/luatex/generic/luaotfload + × https://github.com/lualatex/luaotfload/releases + + If you are uncertain as to how to proceed, then + ask on the lualatex mailing list: + + http://www.tug.org/mailman/listinfo/lualatex-dev + + =============================================== +]], + errcnt) + end + return false, false + end +end + --- stuff to be carried out prior to exit local finalizers = { } @@ -952,6 +1039,7 @@ local process_cmdline = function ( ) -- unit -> jobspec local long_options = { alias = 1, cache = 1, + diagnose = "d", ["dry-run"] = "D", ["flush-lookups"] = "l", fields = 1, @@ -973,7 +1061,7 @@ local process_cmdline = function ( ) -- unit -> jobspec warnings = "w", } - local short_options = "bDfFiIlpquvVhw" + local short_options = "bdDfFiIlpquvVhw" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -1047,6 +1135,8 @@ local process_cmdline = function ( ) -- unit -> jobspec config.luaotfload.prioritize = "texmf" elseif v == "b" then action_pending["blacklist"] = true + elseif v == "d" then + action_pending["diagnose"] = true end end -- cgit v1.2.3 From 6b3ed4455d943fca0606a5e2a18e629c6e56a111 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 7 Jul 2013 17:42:54 +0200 Subject: add git metadata to diagnostic info in luaotfload-tool.lua --- luaotfload-tool.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 5a9e08d..3010653 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -928,11 +928,22 @@ do local verify_files = function (errcnt) out ("Loading file hashes.") - local hashes = require (hash_list) - if not hashes then - out ("Testing %d files for integrity.", nhashes) + local info = require (hash_list) + local hashes = info.hashes + local notes = info.notes + if not hashes or #hashes == 0 then + out ("FAILED: cannot read checksums from %s.", hash_list) + return 1/0 + elseif not notes then + out ("FAILED: cannot read commit metadata from %s.", + hash_list) return 1/0 end + + out ("Luaotfload revision %s.", notes.revision) + out ("Committed by %s.", notes.committer) + out ("Timestamp %s.", notes.timestamp) + local nhashes = #hashes out ("Testing %d files for integrity.", nhashes) for i = 1, nhashes do @@ -953,14 +964,15 @@ do errcnt = errcnt + 1 out ("FAILED: checksum mismatch for file %s.", fname) - out ("Expected %s, got %s.", canonicalsum, sum) + out ("Expected %s.", canonicalsum) + out ("Got %s.", sum) else out ("Ok, %s passed.", fname) end end end end - return errcnt + return errcnt, notes end actions.diagnose = function (job) -- cgit v1.2.3 From 23ae4869772666fc7433ae878159277152cc3c33 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 7 Jul 2013 22:06:16 +0200 Subject: rename mkfilelist to mkstatus --- luaotfload-tool.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 3010653..79f1c26 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -920,7 +920,7 @@ actions.list = function (job) end do - local hash_list = "luaotfload-files" + local status_file = "luaotfload-status" local out = function (...) logs.names_report (false, 0, "diagnose", ...) @@ -928,15 +928,15 @@ do local verify_files = function (errcnt) out ("Loading file hashes.") - local info = require (hash_list) + local info = require (status_file) local hashes = info.hashes local notes = info.notes if not hashes or #hashes == 0 then - out ("FAILED: cannot read checksums from %s.", hash_list) + out ("FAILED: cannot read checksums from %s.", status_file) return 1/0 elseif not notes then out ("FAILED: cannot read commit metadata from %s.", - hash_list) + status_file) return 1/0 end -- cgit v1.2.3 From 5aed3af2d85eb52557d41619e39b4389932beda5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 8 Jul 2013 01:17:16 +0200 Subject: add github repo info to diagnostics in ``luaotfload-tool.lua`` this is still **experimental**. what to expect: * the JSON parser in ``util-jsn`` needs fixing. currently it will fail if an API response contains escaped double quotes. see: ; * requires the ``luasec`` module for https requests; * may break in unexpected ways with connectivity problems, e.g. timeouts; * errors not (yet) cumulative with the other diagnostics; * not yet skippable with ``--diagnose``; * for the time being API requests are unauthorized. acquiring a security token is a TODO. --- luaotfload-tool.lua | 232 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 217 insertions(+), 15 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 79f1c26..825f888 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -38,16 +38,21 @@ kpse.set_program_name "luatex" --doc]]-- + +local kpsefind_file = kpse.find_file local md5sumhexa = md5.sumhexa +local next = next +local osdate = os.date local stringexplode = string.explode local stringformat = string.format local stringlower = string.lower local stringrep = string.rep +local stringsub = string.sub local tableconcat = table.concat local texiowrite_nl = texio.write_nl local texiowrite = texio.write -local kpsefind_file = kpse.find_file - +local tonumber = tonumber +local type = type local runtime if _G.getfenv ~= nil then -- 5.1 or LJ if _G.jit ~= nil then @@ -120,11 +125,13 @@ end config.lualibs = config.lualibs or { } config.lualibs.verbose = false config.lualibs.prefer_merged = true -config.lualibs.load_extended = false +config.lualibs.load_extended = true require "lualibs" +--- dofile "util-jsn.lua" --- awaiting fix -local ioloaddata = io.loaddata +local lua_of_json = utilities.json.tolua +local ioloaddata = io.loaddata --[[doc-- \fileent{luatex-basics-gen.lua} calls functions from the @@ -156,7 +163,7 @@ local help_messages = { ["luaotfload-tool"] = [[ Usage: %s [OPTION]... - + Operations on the LuaTeX font database. This tool is part of the luaotfload package. Valid options are: @@ -217,7 +224,7 @@ The font cache will be written to mkluatexfontdb = [[ Usage: %s [OPTION]... - + Rebuild or update the LuaTeX font database. Valid options: @@ -470,7 +477,7 @@ local display_general = function (fullinfo) val = #fullinfo[key] end elseif mode == "d" then - val = os.date("%F %T", fullinfo[key]) + val = osdate("%F %T", fullinfo[key]) end if not val then val = "" @@ -927,7 +934,7 @@ do end local verify_files = function (errcnt) - out ("Loading file hashes.") + out "Loading file hashes." local info = require (status_file) local hashes = info.hashes local notes = info.notes @@ -975,16 +982,213 @@ do return errcnt, notes end + local check_upstream + + if kpsefind_file ("https.lua", "lua") == nil then + check_upstream = function () + out [[Github API access requires the luasec library. + WARNING: Cannot retrieve repository data. + Grab it from + and retry.]] + end + else + --- github api stuff begin + local https = require "ssl.https" + + local gh_api_root = [[https://api.github.com]] + local release_url = [[https://github.com/lualatex/luaotfload/releases]] + local luaotfload_repo = [[lualatex/luaotfload]] + local user_agent = [[lualatex/luaotfload integrity check]] + local shortbytes = 8 + + local gh_shortrevision = function (rev) + return stringsub (rev, 1, shortbytes) + end + + local gh_encode_parameters = function (parameters) + local acc = {} + for field, value in next, parameters do + --- unsafe, non-urlencoded coz it’s all ascii chars + acc[#acc+1] = field .. "=" .. value + end + return "?" .. tableconcat (acc, "&") + end + + local gh_make_url = function (components, parameters) + local url = tableconcat ({ gh_api_root, + unpack (components) }, + "/") + if parameters then + url = url .. gh_encode_parameters (parameters) + end + return url + end + + local alright = [[HTTP/1.1 200 OK]] + + local gh_api_request = function (...) + local args = {...} + local nargs = #args + local final = args[nargs] + local request = { + url = "", + headers = { ["user-agent"] = user_agent }, + } + if type (final) == "table" then + args[nargs] = nil + request = gh_make_url (args, final) + else + request = gh_make_url (args) + end + + out ("Requesting <%s>.", request) + local response, code, headers, status + = https.request (request) + if status ~= alright then + out "Request failed!" + return false + end + return response + end + + local gh_api_checklimit = function (headers) + local rawlimit = gh_api_request "rate_limit" + local limitdata = lua_of_json (rawlimit) + if not limitdata and limitdata.rate then + out "Cannot parse API rate limit." + return false + end + limitdata = limitdata.rate + + local limit = tonumber (limitdata.limit) + local left = tonumber (limitdata.remaining) + local reset = tonumber (limitdata.reset) + + out ("%d of %d Github API requests left.", left, limit) + if left == 0 then + out ("Cannot make any more API requests.") + out ("Try again later at %s.", osdate ("%F %T", reset)) + end + return true + end + + local gh_tags = function () + out "Fetching tags from repository, please stand by." + local rawtags = gh_api_request ("repos", + luaotfload_repo, + "tags") + local taglist = lua_of_json (rawtags) + if not taglist or #taglist == 0 then + out "Cannot parse response." + return false + end + + local ntags = #taglist + out ("Repository contains %d tags.", ntags) + local _idx, latest = next (taglist) + out ("The most recent release is %s (revision %s).", + latest.name, + gh_shortrevision (latest.commit.sha)) + return latest + end + + local gh_compare = function (head, base) + if base == nil then + base = "HEAD" + end + out ("Fetching comparison between %s and %s, \z + please stand by.", + gh_shortrevision (head), + gh_shortrevision (base)) + local comparison = base .. "..." .. head + local rawstatus = gh_api_request ("repos", + luaotfload_repo, + "compare", + comparison) + local status = lua_of_json (rawstatus) + if not status then + out "Cannot parse response for status request." + return false + end + return status + end + + local gh_news = function (since) + local compared = gh_compare (since) + if not compared then + return false + end + local behind_by = compared.behind_by + local ahead_by = compared.ahead_by + local status = compared.status + out ("Comparison state: %s.", status) + if behind_by > 0 then + out ("Your Luaotfload is %d \z + revisions behind upstream.", + behind_by) + return behind_by + elseif status == "ahead" then + out "Since you are obviously from the future \z + I assume you already know the repository state." + else + out "Everything up to date. \z + Luaotfload is in sync with upstream." + end + return false + end + + local gh_catchup = function (current, latest) + local compared = gh_compare (latest, current) + local ahead_by = tonumber (compared.ahead_by) + if ahead_by > 0 then + local permalink_url = compared.permalink_url + out ("Your Luaotfload is %d revisions \z + behind the most recent release.", + ahead_by) + out ("To view the commit log, visit <%s>.", + permalink_url) + out ("You can grab an up to date tarball at <%s>.", + release_url) + return true + else + out "There weren’t any new releases in the meantime." + out "Luaotfload is up to date." + end + return false + end + + check_upstream = function (current) + local _succ = gh_api_checklimit () + local behind = gh_news (current) + if behind then + local latest = gh_tags () + local _behind = gh_catchup (current, + latest.commit.sha, + latest.name) + end + end + + --- trivium: diff since the first revision as pushed by Élie + --- in 2009 + --- local firstrevision = "c3ccb3ee07e0a67171c24960966ae974e0dd8e98" + --- check_upstream (firstrevision) + end + --- github api stuff end + + actions.diagnose = function (job) local errcnt = 0 - errcnt = verify_files (errcnt) + errcnt, notes = verify_files (errcnt) + --errcnt = check_upstream (notes.revision) + + check_upstream (notes.revision) if errcnt == 0 then --> success out ("Everything appears to be in order, \z you may sleep well.") return true, false - else - out ( [[=============================================== + end + out ( [[=============================================== WARNING =============================================== @@ -1005,10 +1209,8 @@ do http://www.tug.org/mailman/listinfo/lualatex-dev =============================================== -]], - errcnt) - end - return false, false +]], errcnt) + return true, false end end -- cgit v1.2.3 From cfcc97762b232c9cbdb569aa8b3c5c2d82179e2f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 8 Jul 2013 10:49:09 +0200 Subject: make individual diagnostics selectable in luaotfload-tool.lua --- luaotfload-tool.lua | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 825f888..add8c16 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -132,6 +132,7 @@ require "lualibs" local lua_of_json = utilities.json.tolua local ioloaddata = io.loaddata +local tabletohash = table.tohash --[[doc-- \fileent{luatex-basics-gen.lua} calls functions from the @@ -662,7 +663,7 @@ local action_sequence = { "blacklist", "cache", "flush", "generate", "list", "query", } -local action_pending = table.tohash(action_sequence, false) +local action_pending = tabletohash(action_sequence, false) action_pending.loglevel = true --- always set the loglevel action_pending.generate = false --- this is the default action @@ -927,15 +928,11 @@ actions.list = function (job) end do - local status_file = "luaotfload-status" - local out = function (...) logs.names_report (false, 0, "diagnose", ...) end - local verify_files = function (errcnt) - out "Loading file hashes." - local info = require (status_file) + local verify_files = function (errcnt, info) local hashes = info.hashes local notes = info.notes if not hashes or #hashes == 0 then @@ -979,7 +976,7 @@ do end end end - return errcnt, notes + return errcnt end local check_upstream @@ -1175,13 +1172,33 @@ do end --- github api stuff end + local anamneses = { "verify", "repository", } + local status_file = "luaotfload-status" actions.diagnose = function (job) local errcnt = 0 - errcnt, notes = verify_files (errcnt) - --errcnt = check_upstream (notes.revision) + local asked = job.asked_diagnostics + if asked == "all" or asked == "thorough" then + asked = tabletohash (anamneses, true) + else + asked = lpegmatch(split_comma, asked) + asked = tabletohash (asked, true) + end + + out "Loading file hashes." + local info = require (status_file) + + if asked.verify == true then + errcnt = verify_files (errcnt, info) + end +-- if asked.xxx == true then +-- errcnt = xxx (errcnt) +-- end + if asked.repository == true then + --errcnt = check_upstream (info.notes.revision) + check_upstream (info.notes.revision) + end - check_upstream (notes.revision) if errcnt == 0 then --> success out ("Everything appears to be in order, \z @@ -1253,7 +1270,7 @@ local process_cmdline = function ( ) -- unit -> jobspec local long_options = { alias = 1, cache = 1, - diagnose = "d", + diagnose = 1, ["dry-run"] = "D", ["flush-lookups"] = "l", fields = 1, @@ -1275,7 +1292,7 @@ local process_cmdline = function ( ) -- unit -> jobspec warnings = "w", } - local short_options = "bdDfFiIlpquvVhw" + local short_options = "bDfFiIlpquvVhw" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -1349,8 +1366,9 @@ local process_cmdline = function ( ) -- unit -> jobspec config.luaotfload.prioritize = "texmf" elseif v == "b" then action_pending["blacklist"] = true - elseif v == "d" then + elseif v == "diagnose" then action_pending["diagnose"] = true + result.asked_diagnostics = optarg[n] end end -- cgit v1.2.3 From 981c1d5781048d292e222b5a2e934a67218dbb9c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 8 Jul 2013 14:32:46 +0200 Subject: add file permissions check to --diagnose option in luaotfload-tool.lua --- luaotfload-tool.lua | 151 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 143 insertions(+), 8 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index add8c16..e1905f3 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -39,10 +39,16 @@ kpse.set_program_name "luatex" --doc]]-- +local ioopen = io.open local kpsefind_file = kpse.find_file +local lfsattributes = lfs.attributes +local lfsisfile = lfs.isfile +local lfsreadlink = lfs.readlink local md5sumhexa = md5.sumhexa local next = next local osdate = os.date +local osremove = os.remove +local ostype = os.type local stringexplode = string.explode local stringformat = string.format local stringlower = string.lower @@ -53,6 +59,7 @@ local texiowrite_nl = texio.write_nl local texiowrite = texio.write local tonumber = tonumber local type = type + local runtime if _G.getfenv ~= nil then -- 5.1 or LJ if _G.jit ~= nil then @@ -67,7 +74,7 @@ else -- 5.2 end -local C, Ct, P, S = lpeg.C, lpeg.Ct, lpeg.P, lpeg.S +local C, Cg, Ct, P, S = lpeg.C, lpeg.Cg, lpeg.Ct, lpeg.P, lpeg.S local lpegmatch = lpeg.match local loader_file = "luatexbase.loader.lua" @@ -133,6 +140,8 @@ require "lualibs" local lua_of_json = utilities.json.tolua local ioloaddata = io.loaddata local tabletohash = table.tohash +local fileiswritable = file.iswritable +local fileisreadable = file.isreadable --[[doc-- \fileent{luatex-basics-gen.lua} calls functions from the @@ -933,6 +942,7 @@ do end local verify_files = function (errcnt, info) + out "================ verify files =================" local hashes = info.hashes local notes = info.notes if not hashes or #hashes == 0 then @@ -979,14 +989,138 @@ do return errcnt end + local get_tentative_attributes = function (file) + if not lfsisfile (file) then + local chan = ioopen (file, "w") + if chan then + chan:close () + local attributes = lfsattributes (file) + os.remove (file) + return attributes + end + end + end + + local p_permissions = Ct(Cg(Ct(C(1) * C(1) * C(1)), "u") + * Cg(Ct(C(1) * C(1) * C(1)), "g") + * Cg(Ct(C(1) * C(1) * C(1)), "o")) + + local analyze_permissions = function (raw) + return lpegmatch (p_permissions, raw) + end + + local get_permissions = function (t, location) + local attributes = lfsattributes (location) + if not attributes and t == "f" then + attributes = get_tentative_attributes (location) + if not attributes then + return false + end + end + + local permissions + + if fileisreadable (location) then + --- link handling appears to be unnecessary because + --- lfs.attributes() will return the information on + --- the link target. + if mode == "link" then --follow and repeat + location = lfsreadlink (location) + attributes = lfsattributes (location) + end + end + + permissions = analyze_permissions (attributes.permissions) + + return { + location = location, + mode = attributes.mode, + owner = attributes.uid, --- useless on windows + permissions = permissions, + attributes = attributes, + } + end + + local check_conformance = function (spec, permissions, errcnt) + local uid = permissions.attributes.uid + local gid = permissions.attributes.gid + local raw = permissions.attributes.permissions + + out ("Owner: %d, group %d, permissions %s.", uid, gid, raw) + if ostype == "unix" then + if uid == 0 or gid == 0 then + out "Owned by the superuser, permission conflict likely." + errcnt = errcnt + 1 + end + end + + local user = permissions.permissions.u + if spec.r == true then + if user[1] == "r" then + out "Readable: ok." + else + out "Not readable: permissions need fixing." + errcnt = errcnt + 1 + end + end + + if spec.w == true then + if user[2] == "w" + or fileiswritable (permissions.location) then + out "Writable: ok." + else + out "Not writable: permissions need fixing." + errcnt = errcnt + 1 + end + end + + return errcnt + 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 }, + { "f", {"r","w"}, path.index.luc }, + { "f", {"r","w"}, path.lookups.lua }, + { "f", {"r","w"}, path.lookups.luc }, + } + + local check_permissions = function (errcnt) + out [[=============== file permissions ==============]] + for i = 1, #desired_permissions do + local t, spec, path = unpack (desired_permissions[i]) + if type (path) == "function" then + path = path () + end + + spec = tabletohash (spec) + + out ("Checking permissions of %s.", path) + + local permissions = get_permissions (t, path) + if permissions then + --inspect (permissions) + errcnt = check_conformance (spec, permissions, errcnt) + else + errcnt = errcnt + 1 + end + end + return errcnt + end + local check_upstream if kpsefind_file ("https.lua", "lua") == nil then - check_upstream = function () - out [[Github API access requires the luasec library. + check_upstream = function (errcnt) + out [[============= upstream repository ============= + Github API access requires the luasec library. WARNING: Cannot retrieve repository data. Grab it from and retry.]] + return errcnt end else --- github api stuff begin @@ -1155,6 +1289,7 @@ do end check_upstream = function (current) + out "============= upstream repository =============" local _succ = gh_api_checklimit () local behind = gh_news (current) if behind then @@ -1172,7 +1307,7 @@ do end --- github api stuff end - local anamneses = { "verify", "repository", } + local anamneses = { "files", "repository", "permissions" } local status_file = "luaotfload-status" actions.diagnose = function (job) @@ -1188,12 +1323,12 @@ do out "Loading file hashes." local info = require (status_file) - if asked.verify == true then + if asked.files == true then errcnt = verify_files (errcnt, info) end --- if asked.xxx == true then --- errcnt = xxx (errcnt) --- end + if asked.permissions == true then + errcnt = check_permissions (errcnt) + end if asked.repository == true then --errcnt = check_upstream (info.notes.revision) check_upstream (info.notes.revision) -- cgit v1.2.3 From 3e35c3298e7b712c81704df74145754baf1a32df Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 8 Jul 2013 14:49:42 +0200 Subject: add --diagnose to usage info of luaotfload-tool.lua --- luaotfload-tool.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index e1905f3..a5ed717 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -189,6 +189,8 @@ This tool is part of the luaotfload package. Valid options are: -V --version print version and exit -h --help print this message + --diagnose=CHECK run a self test procedure; one of “files”, + “permissions”, or “repository” --alias= force behavior of “luaotfload-tool” or legacy “mkluatexfontdb” -- cgit v1.2.3 From 4ae202183fb9e6cfadb81aefd6a8d26feb3de212 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Jul 2013 22:36:01 +0200 Subject: add short usage message to luaotfload-tool --- luaotfload-tool.lua | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index a5ed717..c3c0f72 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -40,6 +40,7 @@ kpse.set_program_name "luatex" local ioopen = io.open +local iowrite = io.write local kpsefind_file = kpse.find_file local lfsattributes = lfs.attributes local lfsisfile = lfs.isfile @@ -172,7 +173,7 @@ local names_bin = pathdata.index.luc local help_messages = { ["luaotfload-tool"] = [[ -Usage: %s [OPTION]... +Usage: %s [OPTIONS...] Operations on the LuaTeX font database. @@ -255,17 +256,26 @@ The font database will be saved to %s ]], + short = [[ +Usage: luaotfload-tool [--help] [--version] [--verbose=] + [--update] [--force] [--prefer-texmf] + [--find=] [--fuzzy] [--info] [--inspect] + [--list=] [--fields=] + [--cache=] [--flush-lookups] + [--show-blacklist] [--diagnose=] + +Enter 'luaotfload-tool --help' for a larger list of options. +]] } -local help_msg = function ( ) - local template = help_messages[config.luaotfload.self] - or help_messages["luaotfload-tool"] - texiowrite_nl(stringformat(template, - config.luaotfload.self, - names_plain, - names_bin, - caches.getwritablepath ( - config.luaotfload.cache_dir))) +local help_msg = function (version) + local template = help_messages[version] + iowrite(stringformat(template, + config.luaotfload.self, + names_plain, + names_bin, + caches.getwritablepath ( + config.luaotfload.cache_dir))) end local version_msg = function ( ) @@ -685,7 +695,7 @@ actions.loglevel = function (job) logs.set_loglevel(job.log_level) logs.names_report("info", 3, "util", "Setting log level", "%d", job.log_level) - logs.names_report("log", 0, "util", "Lua=%s", _VERSION) + logs.names_report("log", 2, "util", "Lua=%s", _VERSION) return true, true end @@ -695,7 +705,7 @@ actions.version = function (job) end actions.help = function (job) - help_msg() + help_msg (job.help_version or "luaotfload-tool") return true, false end @@ -1510,9 +1520,13 @@ local process_cmdline = function ( ) -- unit -> jobspec end if config.luaotfload.self == "mkluatexfontdb" then + result.help_version = "mkluatexfontdb" action_pending["generate"] = true - result.log_level = math.max(2, result.log_level) + result.log_level = math.max(1, result.log_level) logs.set_logout"stdout" + elseif nopts == 0 then + action_pending["help"] = true + result.help_version = "short" end return result end -- cgit v1.2.3 From 021f0c5e4859e15dc1d24cd232a327fd69446cb1 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Jul 2013 00:46:31 +0200 Subject: fix format specifier in diagnose printer --- luaotfload-tool.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index c3c0f72..060b8a0 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -977,7 +977,7 @@ do local location = kpsefind_file (fname) if not location then errcnt = errcnt + 1 - out ("FAILED: file %d missing.", fname) + out ("FAILED: file %s missing.", fname) else out ("File: %s.", location) local raw = ioloaddata (location) -- cgit v1.2.3 From 12bc6faf98fa9e8fc4ecc1db2cde14ff620b0429 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Jul 2013 18:01:15 +0200 Subject: bump version, update NEWS --- luaotfload-tool.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 060b8a0..96cc9aa 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -4,7 +4,7 @@ -- DESCRIPTION: database functionality -- REQUIREMENTS: luaotfload 2.2 -- AUTHOR: Khaled Hosny, Élie Roux, Philipp Gesang --- VERSION: 2.3 +-- VERSION: 2.3a -- LICENSE: GPL v2 -- MODIFIED: 2013-06-02 19:23:54+0200 ----------------------------------------------------------------------- -- cgit v1.2.3 From 190129ad12d2a5567c9af7932f8632da9be40d2e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Jul 2013 18:14:46 +0200 Subject: consider that scripts are in the scripts/ tree when locating files --- luaotfload-tool.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'luaotfload-tool.lua') diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 96cc9aa..4afd9d1 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -975,6 +975,7 @@ do for i = 1, nhashes do local fname, canonicalsum = unpack (hashes[i]) local location = kpsefind_file (fname) + or kpsefind_file (fname, "texmfscripts") if not location then errcnt = errcnt + 1 out ("FAILED: file %s missing.", fname) -- cgit v1.2.3