Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Feb 3, 2023
1 parent 5f5295e commit 42bad3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions script/filewatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ local m = {}
m._eventList = {}
m._watchings = {}

---@async
---@param path string
---@param recursive boolean
---@param filter? fun(path: string):boolean
---@param filter? async fun(path: string):boolean
function m.watch(path, recursive, filter)
if path == '' or not fs.is_directory(fs.path(path)) then
return function () end
Expand All @@ -46,12 +47,21 @@ 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 in fs.pairs(dir) do
if fs.is_directory(fullpath) then
if not filter or filter(fullpath:string()) then
watch:add(fullpath:string())
log.debug('Watch add:', fullpath:string())
log.trace('Watch add:', fullpath:string())
xpcall(scanDirctory, log.error, fullpath)
end
end
Expand Down
4 changes: 4 additions & 0 deletions script/workspace/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,13 @@ function m.awaitPreload(scp)

if scp.uri and not scp:get('bad root') then
log.info('Scan files at:', scp:getName())
---@async
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true, function (path)
local uri = furi.encode(path)
if m.isIgnored(uri) and not files.isLibrary(uri) then
return false
end
await.delay()
return true
end))
local count = 0
Expand All @@ -331,11 +333,13 @@ function m.awaitPreload(scp)
for _, libMatcher in ipairs(librarys) do
log.info('Scan library at:', libMatcher.uri)
local count = 0
---@async
scp:gc(fw.watch(furi.decode(libMatcher.uri), true, function (path)
local uri = furi.encode(path)
if m.isIgnored(uri) and not files.isLibrary(uri) then
return false
end
await.delay()
return true
end))
scp:addLink(libMatcher.uri)
Expand Down

0 comments on commit 42bad3f

Please sign in to comment.