xrforge-v2/src/.lua/scan.lua

51 lines
1.5 KiB
Lua
Raw Normal View History

local dir = require "opendirectory"
local scan
scan = {
shouldHideFile = function(name)
return name == ".."
or name == "util" -- repository
or name == ".git" -- files
or name == "src" --
or name == "result" --
end,
scan = function()
-- scan dirs
local dref = dir.foreach( app.opts.disk_dir, function(path,stat,state,name,kind,ino,off,attr,fullpath)
if kind == unix.DT_DIR and not scan.shouldHideFile(name) then
local experience = {
path = fullpath,
name = name,
tag = {},
file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
}
app.pub("scan_experience", nil, experience)
print(" ".. fullpath)
-- scan files
local fref = dir.foreach(fullpath, function(path,stat,state,name,kind,ino,off,attr, fullpath)
if kind ~= unix.DT_DIR and not scan.shouldHideFile(name) then
experience.file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
app.pub("scan_experience_file", nil, experience)
local size = attr:size()
trace(" ".. fullpath)
end
end)
fref:close()
end
end)
dref:close()
foreach( app.cache.items, function(k,v)
-- remove file attributes (which are closed already)
v.file.stat = nil
v.file.attr = nil
v.file.state = nil
end)
end
}
return scan