mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-02-08 14:48:25 +00:00
This commit is contained in:
parent
69d5b186a3
commit
499365e2ca
@ -7,6 +7,7 @@ settings = {
|
|||||||
-- logfile = "/tmp/lsyncd",
|
-- logfile = "/tmp/lsyncd",
|
||||||
-- nodaemon = true,
|
-- nodaemon = true,
|
||||||
statusfile = "/tmp/lsyncd.stat",
|
statusfile = "/tmp/lsyncd.stat",
|
||||||
|
statusintervall = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
----
|
----
|
||||||
|
20
lsyncd.c
20
lsyncd.c
@ -410,7 +410,7 @@ static int l_stackdump(lua_State* L);
|
|||||||
* @return (Lua stack) numeric watch descriptor
|
* @return (Lua stack) numeric watch descriptor
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
l_add_watch(lua_State *L)
|
l_inotifyadd(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *path = luaL_checkstring(L, 1);
|
const char *path = luaL_checkstring(L, 1);
|
||||||
lua_Integer wd = inotify_add_watch(inotify_fd, path, standard_event_mask);
|
lua_Integer wd = inotify_add_watch(inotify_fd, path, standard_event_mask);
|
||||||
@ -418,6 +418,19 @@ l_add_watch(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an inotify watch
|
||||||
|
*
|
||||||
|
* @param dir (Lua stack) numeric watch descriptor
|
||||||
|
* @return nil
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
l_inotifyrm(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_Integer wd = luaL_checkinteger(L, 1);
|
||||||
|
inotify_rm_watch(inotify_fd, wd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a message.
|
* Logs a message.
|
||||||
@ -805,20 +818,21 @@ l_configure(lua_State *L)
|
|||||||
|
|
||||||
|
|
||||||
static const luaL_reg lsyncdlib[] = {
|
static const luaL_reg lsyncdlib[] = {
|
||||||
{"add_watch", l_add_watch },
|
|
||||||
{"addtoclock", l_addtoclock },
|
{"addtoclock", l_addtoclock },
|
||||||
{"clockbefore", l_clockbefore },
|
{"clockbefore", l_clockbefore },
|
||||||
{"clockbeforeq", l_clockbeforeq },
|
{"clockbeforeq", l_clockbeforeq },
|
||||||
{"configure", l_configure },
|
{"configure", l_configure },
|
||||||
{"earlier", l_earlier },
|
{"earlier", l_earlier },
|
||||||
{"exec", l_exec },
|
{"exec", l_exec },
|
||||||
|
{"inotifyadd", l_inotifyadd },
|
||||||
|
{"inotifyrm", l_inotifyrm },
|
||||||
{"log", l_log },
|
{"log", l_log },
|
||||||
{"now", l_now },
|
{"now", l_now },
|
||||||
{"writefd", l_writefd },
|
|
||||||
{"realdir", l_realdir },
|
{"realdir", l_realdir },
|
||||||
{"stackdump", l_stackdump },
|
{"stackdump", l_stackdump },
|
||||||
{"subdirs", l_subdirs },
|
{"subdirs", l_subdirs },
|
||||||
{"terminate", l_terminate },
|
{"terminate", l_terminate },
|
||||||
|
{"writefd", l_writefd },
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
87
lsyncd.lua
87
lsyncd.lua
@ -114,27 +114,33 @@ local CountArray = (function()
|
|||||||
t[k_nt][k] = v
|
t[k_nt][k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO
|
-----
|
||||||
local function iwalk(self)
|
-- Walks through all entries in any order.
|
||||||
return ipairs(self[k_nt])
|
--
|
||||||
|
local function walk(self)
|
||||||
|
return pairs(self[k_nt])
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- returns the count
|
-- returns the count
|
||||||
|
--
|
||||||
local function size(self)
|
local function size(self)
|
||||||
return self._size
|
return self._size
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- creates a new count array
|
-- creates a new count array
|
||||||
|
--
|
||||||
local function new()
|
local function new()
|
||||||
-- k_nt is native table, private for this object.
|
-- k_nt is native table, private for this object.
|
||||||
local o = {_size = 0, iwalk = iwalk, size = size, [k_nt] = {} }
|
local o = {_size = 0, walk = walk, size = size, [k_nt] = {} }
|
||||||
setmetatable(o, mt)
|
setmetatable(o, mt)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
-- objects public interface
|
-----
|
||||||
|
-- public interface
|
||||||
|
--
|
||||||
return {new = new}
|
return {new = new}
|
||||||
end)()
|
end)()
|
||||||
|
|
||||||
@ -527,34 +533,24 @@ local Sync = (function()
|
|||||||
local function invokeActions(self, now)
|
local function invokeActions(self, now)
|
||||||
log("Function", "invokeActions('",self.config.name,"',",now,")")
|
log("Function", "invokeActions('",self.config.name,"',",now,")")
|
||||||
if self.processes:size() >= self.config.maxProcesses then
|
if self.processes:size() >= self.config.maxProcesses then
|
||||||
log("Debug", "no new processes")
|
|
||||||
-- no new processes
|
-- no new processes
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for _, d in ipairs(self.delays) do
|
for _, d in ipairs(self.delays) do
|
||||||
log("Debug", "iter")
|
|
||||||
if d.alarm ~= true and lsyncd.clockbefore(now, d.alarm) then
|
if d.alarm ~= true and lsyncd.clockbefore(now, d.alarm) then
|
||||||
-- reached point in stack where delays are in future
|
-- reached point in stack where delays are in future
|
||||||
log("Debug", "waits in future.")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if d.status == "wait" then
|
if d.status == "wait" then
|
||||||
-- found a waiting delay
|
-- found a waiting delay
|
||||||
log("Debug", "invoke")
|
|
||||||
InletControl.set(self)
|
InletControl.set(self)
|
||||||
log("Debug", "invoke2")
|
|
||||||
self.config.action(Inlet)
|
self.config.action(Inlet)
|
||||||
log("Debug", "invoke3")
|
|
||||||
if self.processes:size() >= self.config.maxProcesses then
|
if self.processes:size() >= self.config.maxProcesses then
|
||||||
-- no further processes
|
-- no further processes
|
||||||
log("Debug", "no further processes")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
log("Debug", "finInvoke")
|
|
||||||
end
|
end
|
||||||
log("Debug", "next")
|
|
||||||
end
|
end
|
||||||
log("Debug", "finInvoke")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -731,6 +727,11 @@ local Inotifies = (function()
|
|||||||
-- (directly or by recurse)
|
-- (directly or by recurse)
|
||||||
local wdlist = CountArray.new()
|
local wdlist = CountArray.new()
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- A list indexed by sync's containing a list of all paths
|
||||||
|
-- watches by this sync pointing to the watch descriptor.
|
||||||
|
local syncpaths = {}
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Adds watches for a directory including all subdirectories.
|
-- Adds watches for a directory including all subdirectories.
|
||||||
--
|
--
|
||||||
@ -743,7 +744,7 @@ local Inotifies = (function()
|
|||||||
log("Function",
|
log("Function",
|
||||||
"Inotifies.add(",root,", ",path,", ",recurse,", ",sync,")")
|
"Inotifies.add(",root,", ",path,", ",recurse,", ",sync,")")
|
||||||
-- registers watch
|
-- registers watch
|
||||||
local wd = lsyncd.add_watch(root .. path);
|
local wd = lsyncd.inotifyadd(root .. path);
|
||||||
if wd < 0 then
|
if wd < 0 then
|
||||||
log("Error","Failure adding watch ",dir," -> ignored ")
|
log("Error","Failure adding watch ",dir," -> ignored ")
|
||||||
return
|
return
|
||||||
@ -755,9 +756,16 @@ local Inotifies = (function()
|
|||||||
table.insert(wdlist[wd], {
|
table.insert(wdlist[wd], {
|
||||||
root = root,
|
root = root,
|
||||||
path = path,
|
path = path,
|
||||||
recurse = recurse,
|
recurse = recurse,
|
||||||
sync = sync
|
sync = sync
|
||||||
})
|
})
|
||||||
|
-- create an entry for receival of with sync/path keys
|
||||||
|
local sp = syncpaths[sync]
|
||||||
|
if not sp then
|
||||||
|
sp = {}
|
||||||
|
syncpaths[sync] = sp
|
||||||
|
end
|
||||||
|
sp[path] = wd
|
||||||
|
|
||||||
-- registers and adds watches for all subdirectories
|
-- registers and adds watches for all subdirectories
|
||||||
if recurse then
|
if recurse then
|
||||||
@ -768,6 +776,41 @@ local Inotifies = (function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Removes one event receiver from a directory.
|
||||||
|
--
|
||||||
|
function removeSync(sync, path)
|
||||||
|
local sp = syncpaths[sync]
|
||||||
|
if not sp then
|
||||||
|
error("internal fail, removeSync, nonexisting syncpath-sync.")
|
||||||
|
end
|
||||||
|
local wd = sp[path]
|
||||||
|
if not wd then
|
||||||
|
error("internal fail, removeSync, nonexisting syncpath-wd.")
|
||||||
|
end
|
||||||
|
local ilist = wdlist[wd]
|
||||||
|
if not ilist then
|
||||||
|
error("internal fail, removeSync, nonexisting syncpath-ilist.")
|
||||||
|
end
|
||||||
|
-- TODO optimize for 1 entry only case
|
||||||
|
local i, found
|
||||||
|
for i, v in ipairs(ilist) do
|
||||||
|
if v.sync == sync then
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not found then
|
||||||
|
error("internal fail, removeSync, nonexisiting syncpath-i.")
|
||||||
|
end
|
||||||
|
table.remove(ilist, i)
|
||||||
|
if #ilist == 0 then
|
||||||
|
wdlist[wd] = nil
|
||||||
|
lsyncd.inotifyrm(wd)
|
||||||
|
end
|
||||||
|
sp[path] = nil
|
||||||
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Called when an event has occured.
|
-- Called when an event has occured.
|
||||||
--
|
--
|
||||||
@ -807,15 +850,15 @@ local Inotifies = (function()
|
|||||||
local path = inotify.path .. filename
|
local path = inotify.path .. filename
|
||||||
local path2
|
local path2
|
||||||
if filename2 then
|
if filename2 then
|
||||||
path2 = inotify.path..filename2
|
path2 = inotify.path .. filename2
|
||||||
end
|
end
|
||||||
inotify.sync:delay(etype, time, path, path2)
|
inotify.sync:delay(etype, time, path, path2)
|
||||||
-- adds subdirs for new directories
|
-- adds subdirs for new directories
|
||||||
if inotify.recurse and isdir then
|
if isdir then
|
||||||
if etype == "Create" then
|
if inotify.recurse and etype == "Create" then
|
||||||
add(inotify.root, path, true, inotify.sync)
|
add(inotify.root, path, true, inotify.sync)
|
||||||
elseif etype == "Delete" then
|
elseif etype == "Delete" then
|
||||||
-- TODO
|
removeSync(inotify.sync, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -826,7 +869,7 @@ local Inotifies = (function()
|
|||||||
--
|
--
|
||||||
local function status_report(f)
|
local function status_report(f)
|
||||||
f:write("Watching ",wdlist:size()," directories\n")
|
f:write("Watching ",wdlist:size()," directories\n")
|
||||||
for wd, v in wdlist:iwalk() do
|
for wd, v in wdlist:walk() do
|
||||||
f:write(" ",wd,": ")
|
f:write(" ",wd,": ")
|
||||||
local sep = ""
|
local sep = ""
|
||||||
for _, v in ipairs(v) do
|
for _, v in ipairs(v) do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user