diff options
-rw-r--r-- | server/src/async/scanfiles.lua | 37 | ||||
-rw-r--r-- | server/src/path_filter.lua | 3 |
2 files changed, 25 insertions, 15 deletions
diff --git a/server/src/async/scanfiles.lua b/server/src/async/scanfiles.lua index a9c266b3..6783f97b 100644 --- a/server/src/async/scanfiles.lua +++ b/server/src/async/scanfiles.lua @@ -5,8 +5,14 @@ local fs = require 'bee.filesystem' local path_filter = require 'path_filter' local function scan(root, filter) - local len = #root - local result = {fs.path(root)} + local result = {} + local len = #root:string() + local name = root:string():sub(len+2):gsub('/', '\\') + if filter(name) then + OUT:push('log', '过滤文件:', root:string()) + else + result[#result+1] = root + end local i = 0 return function () i = i + 1 @@ -15,17 +21,12 @@ local function scan(root, filter) return nil end if fs.is_directory(current) then - local name = current:string():sub(len+2):gsub('/', '\\') - if filter(name) then - OUT:push('log', '过滤目录:', current:string()) - else - for path in current:list_directory() do - local name = path:string():sub(len+2):gsub('/', '\\') - if filter(name) then - OUT:push('log', '过滤文件:', path:string()) - else - result[#result+1] = path - end + for path in current:list_directory() do + local name = path:string():sub(len+2):gsub('/', '\\') + if filter(name) then + OUT:push('log', '过滤文件:', path:string()) + else + result[#result+1] = path end end end @@ -33,8 +34,14 @@ local function scan(root, filter) end end -local filter = path_filter(args.ignored) -for path in scan(args.root, filter) do +local ignore = {} +for _, name in ipairs(args.ignored) do + if name:sub(1, 1) ~= '!' then + ignore[#ignore+1] = name + end +end +local filter = path_filter(ignore) +for path in scan(fs.path(args.root), filter) do if path:extension():string() == '.lua' then local buf = io.load(path) if buf then diff --git a/server/src/path_filter.lua b/server/src/path_filter.lua index 2a362677..fb39a6f8 100644 --- a/server/src/path_filter.lua +++ b/server/src/path_filter.lua @@ -25,6 +25,9 @@ local function compile_exp(exp) else exp = '**/' .. exp end + if exp:sub(-1) == '/' then + exp = exp:sub(1, -2) + end local function next(cur) local pos, fn = exp:find('[/\\]+', cur) if not pos then |