Skip to content

Commit bcd5ce9

Browse files
committed
Revert "update filewatch"
This reverts commit 7075ca1.
1 parent 8da1d0d commit bcd5ce9

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

script/filewatch.lua

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,16 @@ local m = {}
3232
m._eventList = {}
3333
m._watchings = {}
3434

35-
---@param path string
36-
---@param recursive boolean
37-
function m.watch(path, recursive)
35+
function m.watch(path)
3836
if path == '' then
3937
return function () end
4038
end
4139
if m._watchings[path] then
4240
m._watchings[path].count = m._watchings[path].count + 1
4341
else
44-
local watch = fw.create()
45-
watch:add(path)
46-
watch:recursive(recursive)
4742
m._watchings[path] = {
4843
count = 1,
49-
watch = watch,
44+
id = fw.add(path),
5045
}
5146
log.debug('fw.add', path)
5247
end
@@ -58,6 +53,7 @@ function m.watch(path, recursive)
5853
removed = true
5954
m._watchings[path].count = m._watchings[path].count - 1
6055
if m._watchings[path].count == 0 then
56+
fw.remove(m._watchings[path].id)
6157
m._watchings[path] = nil
6258
log.debug('fw.remove', path)
6359
end
@@ -79,22 +75,19 @@ end
7975

8076
function m.update()
8177
local collect
82-
for _, watching in pairs(m._watchings) do
83-
local watch = watching.watch
84-
for _ = 1, 10000 do
85-
local ev, path = watch:select()
86-
if not ev then
87-
break
88-
end
89-
log.debug('filewatch:', ev, path)
90-
if not collect then
91-
collect = {}
92-
end
93-
if ev == 'modify' then
94-
collect[path] = (collect[path] or 0) | MODIFY
95-
elseif ev == 'rename' then
96-
collect[path] = (collect[path] or 0) | RENAME
97-
end
78+
for _ = 1, 10000 do
79+
local ev, path = fw.select()
80+
if not ev then
81+
break
82+
end
83+
log.debug('filewatch:', ev, path)
84+
if not collect then
85+
collect = {}
86+
end
87+
if ev == 'modify' then
88+
collect[path] = (collect[path] or 0) | MODIFY
89+
elseif ev == 'rename' then
90+
collect[path] = (collect[path] or 0) | RENAME
9891
end
9992
end
10093

script/provider/provider.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function m.updateConfig(uri)
3636
log.info('Load config from specified', CONFIGPATH)
3737
log.info(inspect(specified))
3838
-- watch directory
39-
filewatch.watch(workspace.getAbsolutePath(uri, CONFIGPATH):gsub('[^/\\]+$', ''), false)
39+
filewatch.watch(workspace.getAbsolutePath(uri, CONFIGPATH):gsub('[^/\\]+$', ''))
4040
config.update(scope.override, specified)
4141
end
4242

script/workspace/workspace.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function m.awaitPreload(scp)
308308

309309
if scp.uri and not scp:get('bad root') then
310310
log.info('Scan files at:', scp:getName())
311-
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true))
311+
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri))))
312312
local count = 0
313313
---@async
314314
native:scan(furi.decode(scp.uri), function (path)
@@ -326,7 +326,7 @@ function m.awaitPreload(scp)
326326
for _, libMatcher in ipairs(librarys) do
327327
log.info('Scan library at:', libMatcher.uri)
328328
local count = 0
329-
scp:gc(fw.watch(furi.decode(libMatcher.uri), true))
329+
scp:gc(fw.watch(furi.decode(libMatcher.uri)))
330330
scp:addLink(libMatcher.uri)
331331
---@async
332332
libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path)

test/other/filewatch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fs.create_directories(path)
99

1010
os.remove((path / 'test.txt'):string())
1111

12-
local _ <close> = fw.watch(path:string(), true)
12+
local _ <close> = fw.watch(path:string())
1313
fsu.saveFile(path / 'test.txt', 'test')
1414

1515
local events

0 commit comments

Comments
 (0)