summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/data-ini.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/data-ini.lua')
-rw-r--r--tex/context/base/mkiv/data-ini.lua53
1 files changed, 13 insertions, 40 deletions
diff --git a/tex/context/base/mkiv/data-ini.lua b/tex/context/base/mkiv/data-ini.lua
index c36e0bb9c..57a800d83 100644
--- a/tex/context/base/mkiv/data-ini.lua
+++ b/tex/context/base/mkiv/data-ini.lua
@@ -8,9 +8,11 @@ if not modules then modules = { } end modules ['data-ini'] = {
local next, type, getmetatable, rawset = next, type, getmetatable, rawset
local gsub, find, gmatch, char = string.gsub, string.find, string.gmatch, string.char
-local filedirname, filebasename, filejoin = file.dirname, file.basename, file.join
+local filedirname, filebasename, filejoin, replacesuffix = file.dirname, file.basename, file.join, file.replacesuffix
local ostype, osname, osuname, ossetenv, osgetenv = os.type, os.name, os.uname, os.setenv, os.getenv
local sortedpairs = table.sortedpairs
+local isfile, currentdir = lfs.isfile, lfs.currentdir
+local expandlink = dir.expandlink
local P, S, R, C, Cs, Cc, lpegmatch = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cs, lpeg.Cc, lpeg.match
@@ -103,31 +105,19 @@ do
environment.ownmain = status and string.match(string.lower(status.banner),"this is ([%a]+)") or "luatex"
end
- local ownbin = environment.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex"
+ local ownbin = environment.ownbin or os.selfbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luametatex"
local ownpath = environment.ownpath or os.selfdir
- ownbin = file.collapsepath(ownbin)
+ ownbin = file.collapsepath(ownbin) -- This one an actually also contain the path!
ownpath = file.collapsepath(ownpath)
-- We need to follow the symlink on osx - texlive. This only works luametatex and
- -- lmtx so we might as wel forget abnotu luatex/mkiv there. The regular context
- -- installation doesn't have this link issue.
+ -- lmtx so we might as wel forget about luatex/mkiv there. The regular context
+ -- installation doesn't have this link issue. I tried several variants but in the
+ -- end the chdir variants was most reliable. Everything else is ugly. (Experimtal
+ -- code is in data-osx.lua).
- local symlinktarget = lfs.symlinktarget
-
- if symlinktarget then
- while true do
- local new = symlinktarget(ownpath) or ownpath
- if new == ownpath then
- break
- else
- ownpath = new
- end
- end
- ownpath = file.collapsepath(ownpath)
- else
- lfs.symlinktarget = function() return nil end -- forget about it, luatex is frozen
- end
+ ownpath = expandlink(ownpath,trace_locating and report_initialization)
if not ownpath or ownpath == "" or ownpath == "unset" then
ownpath = args[-1] or arg[-1]
@@ -142,31 +132,14 @@ do
end
if not ownpath or ownpath == "" then
if os.binsuffix ~= "" then
- binary = file.replacesuffix(binary,os.binsuffix)
+ binary = replacesuffix(binary,os.binsuffix)
end
local path = osgetenv("PATH")
if path then
for p in gmatch(path,"[^"..io.pathseparator.."]+") do
local b = filejoin(p,binary)
- if lfs.isfile(b) then
- -- we assume that after changing to the path the currentdir function
- -- resolves to the real location and use this side effect here; this
- -- trick is needed because on the mac installations use symlinks in the
- -- path instead of real locations
- local olddir = lfs.currentdir()
- if lfs.chdir(p) then
- local pp = lfs.currentdir()
- if trace_locating and p ~= pp then
- report_initialization("following symlink %a to %a",p,pp)
- end
- ownpath = pp
- lfs.chdir(olddir)
- else
- if trace_locating then
- report_initialization("unable to check path %a",p)
- end
- ownpath = p
- end
+ if isfile(b) then
+ ownpath = expandlink(p,trace_locating and report_initialization)
break
end
end