[latex3-commits] [l3svn] 01/09: allow for subdirectory globbing

noreply at latex-project.org noreply at latex-project.org
Sun Jun 25 09:30:21 CEST 2017

This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

commit f3efdc9c59fab4a4c5fc079424ba00b534dd9966
Author: XZS <d.f.fischer at web.de>
Date:   Fri Apr 14 16:17:42 2017 +0200

    allow for subdirectory globbing
    The new function tree wraps filelist, extending it to process not only
    files in the given directory, but also the whole subdirectory hierarchy.
    Its name is derived from the command-line tool "tree", which is to "ls"
    what the tree function is to filelist.
    It could serve as a drop-in replacement for filelist in all places, but
    is only carefully applied as other functions are not yet prepared to
    deal with paths in the place of simple file names. For now, it is only
    employed with copying, enabling the user to collect files from different
    location to be combined for unpacking, typesetting or testing.
 l3build/l3build.lua |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/l3build/l3build.lua b/l3build/l3build.lua
index 62d0c96..5abd4ef 100644
--- a/l3build/l3build.lua
+++ b/l3build/l3build.lua
@@ -490,7 +490,7 @@ end
 -- Copy files 'quietly'
 function cp(glob, source, dest)
   local errorlevel
-  for _,i in ipairs(filelist(source, glob)) do
+  for i,_ in pairs(tree(source, glob)) do
     local source = source .. "/" .. i
     if os_type == "windows" then
       if lfs_attributes(source)["mode"] == "directory" then
@@ -563,6 +563,28 @@ function filelist(path, glob)
   return files
+-- Does what filelist does, but can also glob subdirectories. In the returned
+-- table, the keys are paths relative to the given starting path, the values
+-- are their counterparts relative to the current working directory.
+function tree(path, glob)
+  function cropdots(path)
+    return gsub(gsub(path, "^%./", ""), "/%./", "/")
+  end
+  dirs = {["."]=cropdots(path)}
+  for pattern in gmatch(cropdots(glob), "[^/]+") do
+    local newdirs = {}
+    for path, dir in pairs(dirs) do
+      for _, file in ipairs(filelist(dir, pattern)) do
+        if file ~= "." and file ~= ".." then
+          newdirs[path .. "/" .. file] = dir .. "/" .. file
+        end
+      end
+    end
+    dirs = newdirs
+  end
+  return dirs
 function mkdir(dir)
   if os_type == "windows" then
     -- Windows (with the extensions) will automatically make directory trees

To stop receiving notification emails like this one, please contact
the administrator of this repository.

More information about the latex3-commits mailing list