[mdir] Switch to async call
mdir is only semi-tested that it does work: I have not set up maildir to check if the matching patterns are correct
This commit is contained in:
parent
06d96a92ba
commit
7ae6a84b52
|
@ -16,7 +16,7 @@ Added:
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
|
|
||||||
- [volume,gmail,battery(FreeBSD)] Deprecate `io.popen`
|
- [volume,gmail,bat_freebsd,mem_freebsd,net_freebsd,mdir] Deprecate `io.popen`
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local io = { popen = io.popen }
|
local type = type
|
||||||
local setmetatable = setmetatable
|
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require"vicious.helpers"
|
||||||
|
local spawn = require"vicious.spawn"
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,27 +18,25 @@ local mdir_all = {}
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Maildir widget type
|
-- {{{ Maildir widget type
|
||||||
local function worker(format, warg)
|
function mdir_all.async(format, warg, callback)
|
||||||
if not warg then return end
|
if type(warg) ~= "table" then return callback{} end
|
||||||
|
local starting_points = ""
|
||||||
-- Initialize counters
|
for i,dir in ipairs(warg) do
|
||||||
local count = { new = 0, cur = 0 }
|
starting_points = starting_points .. " " .. helpers.shellquote(dir)
|
||||||
|
|
||||||
for i=1, #warg do
|
|
||||||
quoted_path = helpers.shellquote(warg[i])
|
|
||||||
-- Recursively find new messages
|
|
||||||
local f = io.popen("find "..quoted_path.." -type f -wholename '*/new/*'")
|
|
||||||
for line in f:lines() do count.new = count.new + 1 end
|
|
||||||
f:close()
|
|
||||||
|
|
||||||
-- Recursively find "old" messages lacking the Seen flag
|
|
||||||
local f = io.popen("find "..quoted_path.." -type f -regex '.*/cur/.*2,[^S]*$'")
|
|
||||||
for line in f:lines() do count.cur = count.cur + 1 end
|
|
||||||
f:close()
|
|
||||||
end
|
end
|
||||||
|
if starting_points == "" then return callback{ 0, 0 } end
|
||||||
|
|
||||||
return {count.new, count.cur}
|
local new, cur = 0, 0
|
||||||
|
spawn.with_line_callback(
|
||||||
|
"find" .. starting_points .. " -type f -regex '.*/cur/.*2,[^S]*$';",
|
||||||
|
{ stdout = function (filename) cur = cur + 1 end,
|
||||||
|
output_done = function ()
|
||||||
|
spawn.with_line_callback(
|
||||||
|
"find" .. starting_points .. " -type f -path '*/new/*';",
|
||||||
|
{ stdout = function (filename) new = new + 1 end,
|
||||||
|
output_done = function () callback{ new, cur } end })
|
||||||
|
end })
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(mdir_all, { __call = function(_, ...) return worker(...) end })
|
return helpers.setasyncall(mdir_all)
|
||||||
|
|
Loading…
Reference in New Issue