diff options
m--------- | 3rd/bee.lua | 0 | ||||
-rw-r--r-- | script/filewatch.lua | 30 | ||||
-rw-r--r-- | script/meta/bee/filesystem.lua | 2 | ||||
-rw-r--r-- | script/meta/bee/filewatch.lua | 32 |
4 files changed, 37 insertions, 27 deletions
diff --git a/3rd/bee.lua b/3rd/bee.lua -Subproject c353e26453d80a122f69a03476a7599eb2c51e7 +Subproject eefd184a7febb32f3e02826d32458d6352644d1 diff --git a/script/filewatch.lua b/script/filewatch.lua index 1ccb66ce..f9390287 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 5ffeda4a..c4267b97 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 00000000..b5211355 --- /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 |