aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2022-01-03 15:05:57 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2022-01-09 23:20:47 +0100
commit5b154c189fd6213b7e9bd2f5197e2550607f86f6 (patch)
tree2087b4937de8887e8eef174b1c6c7dfa87f3b17b
parent143b389365aec6bd3b16800d9f54cb92f87f42e7 (diff)
downloadlite-xl-5b154c189fd6213b7e9bd2f5197e2550607f86f6.tar.gz
lite-xl-5b154c189fd6213b7e9bd2f5197e2550607f86f6.zip
First version of paths in ignore_files
Works correctly and the logic seems sound even if somewhat quirky. `^%.` match any file of directory whose basename begins with a dot. `^/node_modules$/"` match a directory named `node_modules` at the project's root. Note that the final '/' needs to be at the end. The '/' after the '^' needs to be there to trigger a match of the full path filename so we are sure it is at the root. PROBLEM: the '/' to trigger full path match could be in a pattern's special expression like: [^/] `^%.git$/` match any directory name '.git' anywhere in the project. `^/%.git$/` match a directory named '.git' only at the project's root. `^/subprojects/.+/` match any directory in a top-level folder named "subprojects". `^/build/` match any top level directory whose name begins with "build" PROBLEM: may be surprising, one may expects it matches only a directory named 'build'. It actually acts like it was `^/build.*/`.
-rw-r--r--data/core/init.lua31
1 files changed, 29 insertions, 2 deletions
diff --git a/data/core/init.lua b/data/core/init.lua
index 52f4112a..fe4c75be 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -122,10 +122,37 @@ local function compare_file(a, b)
end
+
+
+
+
local function fileinfo_pass_filter(info)
+ if info.size >= config.file_size_limit * 1e6 then return false end
local basename = common.basename(info.filename)
- return (info.size < config.file_size_limit * 1e6 and
- not common.match_pattern(basename, config.ignore_files))
+ -- replace '\' with '/' for Windows where PATHSEP = '\'
+ local fullname = "/" .. info.filename:gsub("\\", "/")
+ local ipatterns = config.ignore_files
+ -- config.ignore_files could be a simple string...
+ if type(ipatterns) ~= "table" then ipatterns = {ipatterns} end
+ for _, pattern in ipairs(ipatterns) do
+ local is_path_like = pattern:match("/[^/]") -- contains a slash but not at the end
+ local dir_pass = true
+ if pattern:match("(.+)/$") then
+ dir_pass = (info.type == "dir")
+ -- the final '/' should not participate to the match.
+ pattern = pattern:match("(.+)/$")
+ end
+ if is_path_like then
+ if fullname:match(pattern) and dir_pass then
+ return false
+ end
+ else
+ if basename:match(pattern) and dir_pass then
+ return false
+ end
+ end
+ end
+ return true
end