aboutsummaryrefslogtreecommitdiffhomepage
path: root/core/lfs_ext.lua
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2017-06-21 14:56:35 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2017-06-21 14:56:35 -0400
commit30064e7ad7411daf96770111dab21690b5fa54b2 (patch)
tree7daea49bd840bcb2886163de227f26e4dcb15cc2 /core/lfs_ext.lua
parent813ae79a3dae80d875920e776a1d315fcc127435 (diff)
Correctly handle multiple '!' patterns in file filters.
This allows for specific file and folder includes.
Diffstat (limited to 'core/lfs_ext.lua')
-rw-r--r--core/lfs_ext.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/core/lfs_ext.lua b/core/lfs_ext.lua
index 31bb2f94..4367f070 100644
--- a/core/lfs_ext.lua
+++ b/core/lfs_ext.lua
@@ -30,14 +30,16 @@ local function exclude(file, filter)
if not filter then return false end
local ext = filter.extensions
if ext and ext[file:match('[^%.]+$')] then return true end
+ local include -- track any match from a set of '!...' patterns
for i = 1, #filter do
local patt = filter[i]
if patt:sub(1, 1) ~= '!' then
if file:find(patt) then return true end
- else
- if not file:find(patt:sub(2)) then return true end
+ elseif not include then
+ include = file:find(patt:sub(2)) ~= nil
end
end
+ if type(include) == 'boolean' and not include then return true end
return filter.symlink and lfs_symlinkattributes(file, 'mode') == 'link'
end
@@ -57,8 +59,9 @@ end
-- + Optional `folders.symlink` flag that when `true`, excludes symlinked
-- directories.
--
--- Any filter patterns starting with '!' exclude files and directories that do
--- not match the pattern that follows.
+-- Any filter patterns starting with '!' include files and directories that
+-- match the pattern that follows. This is useful for filtering out all files
+-- and directories except a select few.
-- @param dir The directory path to iterate over.
-- @param f Function to call with each full file path found. If *f* returns
-- `false` explicitly, iteration ceases.