diff options
author | Karl Berry <karl@freefriends.org> | 2019-02-28 15:11:56 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-02-28 15:11:56 +0000 |
commit | cc17ad601696f5cf966c8a0b9d79144cd42828a6 (patch) | |
tree | f6007b9b2f886d942f9b30b4797e8718001f65bd /Master/texmf-dist/tex/context/base/mkiv/l-dir.lua | |
parent | e298746bb92cdf7e87bc3b5b9bd973b6c429a47f (diff) |
context for tl19
git-svn-id: svn://tug.org/texlive/trunk@50165 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/l-dir.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/l-dir.lua | 82 |
1 files changed, 45 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua b/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua index bc691d53635..b0b2c52836a 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua @@ -75,7 +75,8 @@ function dir.current() return (gsub(currentdir(),"\\","/")) end --- somewhat optimized +-- The next one is somewhat optimized but still slow but it's a pitty that the iterator +-- doesn't return a mode too. local function glob_pattern_function(path,patt,recurse,action) if isdir(path) then @@ -89,6 +90,7 @@ local function glob_pattern_function(path,patt,recurse,action) usedpath = path end local dirs + local nofdirs = 0 for name in walkdir(usedpath) do if name ~= "." and name ~= ".." then local full = path .. name @@ -98,16 +100,18 @@ local function glob_pattern_function(path,patt,recurse,action) action(full) end elseif recurse and mode == "directory" then - if not dirs then - dirs = { full } + if dirs then + nofdirs = nofdirs + 1 + dirs[nofdirs] = full else - dirs[#dirs+1] = full + nofdirs = 1 + dirs = { full } end end end end if dirs then - for i=1,#dirs do + for i=1,nofdirs do glob_pattern_function(dirs[i],patt,recurse,action) end end @@ -118,38 +122,41 @@ local function glob_pattern_table(path,patt,recurse,result) if not result then result = { } end - if isdir(path) then - local usedpath - if path == "/" then - usedpath = "/." - elseif not find(path,"/$") then - usedpath = path .. "/." - path = path .. "/" - else - usedpath = path - end - local dirs - for name in walkdir(usedpath) do - if name ~= "." and name ~= ".." then - local full = path .. name - local mode = attributes(full,'mode') - if mode == 'file' then - if not patt or find(full,patt) then - result[#result+1] = full - end - elseif recurse and mode == "directory" then - if not dirs then - dirs = { full } - else - dirs[#dirs+1] = full - end + local usedpath + if path == "/" then + usedpath = "/." + elseif not find(path,"/$") then + usedpath = path .. "/." + path = path .. "/" + else + usedpath = path + end + local dirs + local nofdirs = 0 + local noffiles = #result + for name, a in walkdir(usedpath) do + if name ~= "." and name ~= ".." then + local full = path .. name + local mode = attributes(full,'mode') + if mode == 'file' then + if not patt or find(full,patt) then + noffiles = noffiles + 1 + result[noffiles] = full + end + elseif recurse and mode == "directory" then + if dirs then + nofdirs = nofdirs + 1 + dirs[nofdirs] = full + else + nofdirs = 1 + dirs = { full } end end end - if dirs then - for i=1,#dirs do - glob_pattern_table(dirs[i],patt,recurse,result) - end + end + if dirs then + for i=1,nofdirs do + glob_pattern_table(dirs[i],patt,recurse,result) end end return result @@ -160,12 +167,13 @@ local function globpattern(path,patt,recurse,method) if patt and sub(patt,1,-3) == path then patt = false end + local okay = isdir(path) if kind == "function" then - return glob_pattern_function(path,patt,recurse,method) + return okay and glob_pattern_function(path,patt,recurse,method) or { } elseif kind == "table" then - return glob_pattern_table(path,patt,recurse,method) + return okay and glob_pattern_table(path,patt,recurse,method) or method else - return glob_pattern_table(path,patt,recurse,{ }) + return okay and glob_pattern_table(path,patt,recurse,{ }) or { } end end |