diff --git a/3rd/bee.lua b/3rd/bee.lua index c353e2645..eefd184a7 160000 --- a/3rd/bee.lua +++ b/3rd/bee.lua @@ -1 +1 @@ -Subproject commit c353e26453d80a122f69a03476a7599eb2c51e70 +Subproject commit eefd184a7febb32f3e02826d32458d6352644d18 diff --git a/script/filewatch.lua b/script/filewatch.lua index 1ccb66ce7..f9390287a 100644 --- a/script/filewatch.lua +++ b/script/filewatch.lua @@ -35,7 +35,7 @@ m._watchings = {} ---@async ---@param path string ---@param recursive boolean ----@param filter? async fun(path: string):boolean +---@param filter? fun(path: string):boolean function m.watch(path, recursive, filter) if path == '' or not fs.is_directory(fs.path(path)) then return function () end @@ -47,31 +47,9 @@ function m.watch(path, recursive, filter) watch:add(path) log.debug('Watch add:', path) if recursive then - local count = 1 - ---@async - local function scanDirctory(dir) - count = count + 1 - if count % 10 == 0 then - await.delay() - if count % 100 == 0 then - log.warn('Watching so many dirs:', count, dir:string()) - end - end - for fullpath, status in fs.pairs(dir) do - local st = status:type() - if st == 'directory' - or st == 'symlink' - or st == 'junction' then - if not filter or filter(fullpath:string()) then - watch:add(fullpath:string()) - log.trace('Watch add:', fullpath:string()) - xpcall(scanDirctory, log.error, fullpath) - end - end - end - end - - xpcall(scanDirctory, log.error, fs.path(path)) + watch:set_filter(filter) + watch:set_follow_symlinks(true) + watch:set_recursive(true) end m._watchings[path] = { count = 1, diff --git a/script/meta/bee/filesystem.lua b/script/meta/bee/filesystem.lua index 5ffeda4ae..c4267b976 100644 --- a/script/meta/bee/filesystem.lua +++ b/script/meta/bee/filesystem.lua @@ -35,7 +35,7 @@ local fsStatus = {} function fsStatus:type() end ----@class fs +---@class bee.filesystem local fs = {} ---@class fs.copy_options diff --git a/script/meta/bee/filewatch.lua b/script/meta/bee/filewatch.lua new file mode 100644 index 000000000..b5211355e --- /dev/null +++ b/script/meta/bee/filewatch.lua @@ -0,0 +1,32 @@ +---@meta + +---@class bee.filewatch.instance +local instance = {} + +---@param path string +function instance:add(path) +end + +---@param enable boolean +---@return boolean +function instance:set_recursive(enable) +end + +---@param enable boolean +---@return boolean +function instance:set_follow_symlinks(enable) +end + +---@param callback? fun(path: string):boolean +---@return boolean +function instance:set_filter(callback) +end + +---@class bee.filewatch +local fw = {} + +---@return bee.filewatch.instance +function fw.create() +end + +return fw