From 5b154c189fd6213b7e9bd2f5197e2550607f86f6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 3 Jan 2022 15:05:57 +0100 Subject: [PATCH] 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.*/`. --- data/core/init.lua | 31 +++++++++++++++++++++++++++++-- 1 file 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