diff options
Diffstat (limited to 'server/src/async')
-rw-r--r-- | server/src/async/async.lua | 6 | ||||
-rw-r--r-- | server/src/async/scanfiles.lua | 106 |
2 files changed, 33 insertions, 79 deletions
diff --git a/server/src/async/async.lua b/server/src/async/async.lua index 953cf5cf..b385aac8 100644 --- a/server/src/async/async.lua +++ b/server/src/async/async.lua @@ -72,12 +72,12 @@ end local function callback(id, running) if running.callback then while true do - local ok, result = running.task.response:pop() - if not ok then + local results = table.pack(running.task.response:pop()) + if not results[1] then break end -- TODO 封装成对象 - local suc, destroy = xpcall(running.callback, log.error, result) + local suc, destroy = xpcall(running.callback, log.error, table.unpack(results, 2)) if not suc or destroy then RunningList[id] = nil IdlePool[#IdlePool+1] = running.task diff --git a/server/src/async/scanfiles.lua b/server/src/async/scanfiles.lua index c242dcfe..a9c266b3 100644 --- a/server/src/async/scanfiles.lua +++ b/server/src/async/scanfiles.lua @@ -2,92 +2,46 @@ local args = ... require 'utility' local fs = require 'bee.filesystem' -local root = fs.absolute(fs.path(args.root)) - -local function glob_compile(pattern) - return ("^%s$"):format(pattern:gsub("[%^%$%(%)%%%.%[%]%+%-%?]", "%%%0"):gsub("%*", ".*")) -end -local function glob_match(pattern, target) - return target:match(pattern) ~= nil -end - -local function accept_path(t, path) - if t[path:string()] then - return - end - t[#t+1] = path:string() - t[path:string()] = #t -end -local function expand_dir(t, pattern, dir) - if not fs.exists(dir) then - return - end - for file in dir:list_directory() do - if fs.is_directory(file) then - expand_dir(t, pattern, file) - else - if glob_match(pattern, file:filename():string():lower()) then - accept_path(t, file) - end +local path_filter = require 'path_filter' + +local function scan(root, filter) + local len = #root + local result = {fs.path(root)} + local i = 0 + return function () + i = i + 1 + local current = result[i] + if not current then + return nil end - end -end -local function expand_path(t, root, source) - if source:sub(1, 1) == '/' then - source = source:sub(2) - end - local path = root / source - if source:find("*", 1, true) == nil then - accept_path(t, path) - return - end - local filename = path:filename():string():lower() - local pattern = glob_compile(filename) - expand_dir(t, pattern, path:parent_path()) -end -local function get_sources(root, sources) - local result = {} - local ignore = {} - for _, source in ipairs(sources) do - if source:sub(1,1) ~= "!" then - expand_path(result, root, source) - else - expand_path(ignore, root, source:sub(2)) - end - end - for _, path in ipairs(ignore) do - local pos = result[path] - if pos then - result[pos] = result[#result] - result[result[pos]] = pos - result[path] = nil - result[#result] = nil + 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 + end + end end + return current end - return result end -local function computePath() - local ignore = { '.git' } - - - for name in pairs(args.ignore) do - ignore[#ignore+1] = name:lower() - end - - return get_sources(root, ignore) -end - -local ignored = computePath() - -for path in io.scan(root, ignored) do +local filter = path_filter(args.ignored) +for path in scan(args.root, filter) do if path:extension():string() == '.lua' then local buf = io.load(path) if buf then - OUT:push { + OUT:push('file', { path = fs.absolute(path):string(), buf = buf, - } + }) end end end |