diff options
Diffstat (limited to 'macros/luatex/generic/lualibs/lualibs-dir.lua')
-rw-r--r-- | macros/luatex/generic/lualibs/lualibs-dir.lua | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/macros/luatex/generic/lualibs/lualibs-dir.lua b/macros/luatex/generic/lualibs/lualibs-dir.lua index ac8e2f4e8e..3164068505 100644 --- a/macros/luatex/generic/lualibs/lualibs-dir.lua +++ b/macros/luatex/generic/lualibs/lualibs-dir.lua @@ -21,7 +21,8 @@ local dir = dir local lfs = lfs local attributes = lfs.attributes -local walkdir = lfs.dir +----- walkdir = lfs.dir +local scandir = lfs.dir local isdir = lfs.isdir -- not robust, will be overloaded anyway local isfile = lfs.isfile -- not robust, will be overloaded anyway local currentdir = lfs.currentdir @@ -69,6 +70,20 @@ else end +-- safeguard + +local isreadable = file.isreadable + +local walkdir = function(p,...) + if isreadable(p.."/.") then + return scandir(p,...) + else + return function() end + end +end + +lfs.walkdir = walkdir + -- handy function dir.current() @@ -197,7 +212,7 @@ local function collectpattern(path,patt,recurse,result) if not find(path,"/$") then path = path .. '/' end - for name in scanner, first do -- cna be optimized + for name in scanner, first do -- can be optimized if name == "." then -- skip elseif name == ".." then @@ -596,6 +611,27 @@ do end + -- This go there anc check works okay in tricky situation as we encounter + -- on osx, where tex installations use rather complex chains of links. + + function dir.expandlink(dir,report) + local curdir = currentdir() + local trace = type(report) == "function" + if chdir(dir) then + local newdir = currentdir() + if newdir ~= dir and trace then + report("following symlink %a to %a",dir,newdir) + end + chdir(curdir) + return newdir + else + if trace then + report("unable to check path %a",dir) + end + return dir + end + end + end file.expandname = dir.expandname -- for convenience |