Skip to content

Commit 4e56523

Browse files
committed
move filewatch into C
#1872
1 parent 5eee353 commit 4e56523

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

script/filewatch.lua

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ m._watchings = {}
3535
---@async
3636
---@param path string
3737
---@param recursive boolean
38-
---@param filter? async fun(path: string):boolean
38+
---@param filter? fun(path: string):boolean
3939
function m.watch(path, recursive, filter)
4040
if path == '' or not fs.is_directory(fs.path(path)) then
4141
return function () end
@@ -47,31 +47,9 @@ function m.watch(path, recursive, filter)
4747
watch:add(path)
4848
log.debug('Watch add:', path)
4949
if recursive then
50-
local count = 1
51-
---@async
52-
local function scanDirctory(dir)
53-
count = count + 1
54-
if count % 10 == 0 then
55-
await.delay()
56-
if count % 100 == 0 then
57-
log.warn('Watching so many dirs:', count, dir:string())
58-
end
59-
end
60-
for fullpath, status in fs.pairs(dir) do
61-
local st = status:type()
62-
if st == 'directory'
63-
or st == 'symlink'
64-
or st == 'junction' then
65-
if not filter or filter(fullpath:string()) then
66-
watch:add(fullpath:string())
67-
log.trace('Watch add:', fullpath:string())
68-
xpcall(scanDirctory, log.error, fullpath)
69-
end
70-
end
71-
end
72-
end
73-
74-
xpcall(scanDirctory, log.error, fs.path(path))
50+
watch:set_filter(filter)
51+
watch:set_follow_symlinks(true)
52+
watch:set_recursive(true)
7553
end
7654
m._watchings[path] = {
7755
count = 1,

script/meta/bee/filesystem.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ local fsStatus = {}
3535
function fsStatus:type()
3636
end
3737

38-
---@class fs
38+
---@class bee.filesystem
3939
local fs = {}
4040

4141
---@class fs.copy_options

script/meta/bee/filewatch.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---@meta
2+
3+
---@class bee.filewatch.instance
4+
local instance = {}
5+
6+
---@param path string
7+
function instance:add(path)
8+
end
9+
10+
---@param enable boolean
11+
---@return boolean
12+
function instance:set_recursive(enable)
13+
end
14+
15+
---@param enable boolean
16+
---@return boolean
17+
function instance:set_follow_symlinks(enable)
18+
end
19+
20+
---@param callback? fun(path: string):boolean
21+
---@return boolean
22+
function instance:set_filter(callback)
23+
end
24+
25+
---@class bee.filewatch
26+
local fw = {}
27+
28+
---@return bee.filewatch.instance
29+
function fw.create()
30+
end
31+
32+
return fw

0 commit comments

Comments
 (0)