summaryrefslogtreecommitdiff
path: root/xmake/core/base/os.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/core/base/os.lua')
-rw-r--r--xmake/core/base/os.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 005f18a70..89be6d638 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -423,8 +423,14 @@ function os.match(pattern, mode, opt)
return os._async_task().match(pattern, mode)
end
- -- extract callback
- local callback = type(opt) == "function" and opt or (type(opt) == "table" and opt.callback or nil)
+ -- extract callback and the maximum recursion level
+ local callback, maxrecursion
+ if type(opt) == "function" then
+ callback = opt
+ elseif type(opt) == "table" then
+ callback = opt.callback
+ maxrecursion = opt.recursion
+ end
-- support path instance
pattern = tostring(pattern)
@@ -493,7 +499,9 @@ function os.match(pattern, mode, opt)
-- limit recursion level: src/*/*.c
local recursion = 0
if pattern:find("**", 1, true) then
- recursion = -1
+ -- we can also limit the recursion level of `**`, it may be very slow
+ -- in a deep directory tree, e.g. os.files("src/**.c", {recursion = 2})
+ recursion = maxrecursion or -1
else
-- "src/*/*.c" -> "*/" -> recursion level: 1
-- "src/*/main.c" -> "*/" -> recursion level: 1
@@ -504,6 +512,9 @@ function os.match(pattern, mode, opt)
recursion = seps
end
end
+ if maxrecursion and recursion > maxrecursion then
+ recursion = maxrecursion
+ end
end
-- convert pattern to a lua pattern