This commit is contained in:
Axel Kittenberger 2010-11-06 15:08:17 +00:00
parent 610a77b1ec
commit f5d7b7a94b
2 changed files with 49 additions and 57 deletions

View File

@ -40,18 +40,11 @@
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
/**
* Macros to compare times() values
* (borrowed from linux/jiffies.h)
*
* time_after(a,b) returns true if the time a is after time b.
*/
#define time_after(a,b) ((long)(b) - (long)(a) < 0) #define time_after(a,b) ((long)(b) - (long)(a) < 0)
#define time_before(a,b) time_after(b,a) #define time_before(a,b) time_after(b,a)
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
#define time_before_eq(a,b) time_after_eq(b,a) #define time_before_eq(a,b) time_after_eq(b,a)
/** /**
* Event types core sends to runner. * Event types core sends to runner.
*/ */
@ -488,7 +481,7 @@ l_log(lua_State *L)
* @return the true if time1 <= time2 * @return the true if time1 <= time2
*/ */
static int static int
l_is_before_eq(lua_State *L) l_clockbeforeq(lua_State *L)
{ {
clock_t t1 = (clock_t) luaL_checkinteger(L, 1); clock_t t1 = (clock_t) luaL_checkinteger(L, 1);
clock_t t2 = (clock_t) luaL_checkinteger(L, 2); clock_t t2 = (clock_t) luaL_checkinteger(L, 2);
@ -531,7 +524,7 @@ l_now(lua_State *L)
* TODO * TODO
*/ */
static int static int
l_addto_clock(lua_State *L) l_addtoclock(lua_State *L)
{ {
clock_t c1 = luaL_checkinteger(L, 1); clock_t c1 = luaL_checkinteger(L, 1);
clock_t c2 = luaL_checkinteger(L, 2); clock_t c2 = luaL_checkinteger(L, 2);
@ -611,7 +604,7 @@ l_exec(lua_State *L)
* @return absolute path of directory * @return absolute path of directory
*/ */
static int static int
l_real_dir(lua_State *L) l_realdir(lua_State *L)
{ {
luaL_Buffer b; luaL_Buffer b;
char *cbuf; char *cbuf;
@ -690,7 +683,7 @@ l_stackdump(lua_State* L)
* @return (Lua stack) a table of directory names. * @return (Lua stack) a table of directory names.
*/ */
static int static int
l_sub_dirs (lua_State *L) l_subdirs (lua_State *L)
{ {
const char * dirname = luaL_checkstring(L, 1); const char * dirname = luaL_checkstring(L, 1);
DIR *d; DIR *d;
@ -780,7 +773,7 @@ l_terminate(lua_State *L)
* when a process finishes. * when a process finishes.
*/ */
int int
l_wait_pids(lua_State *L) l_waitpids(lua_State *L)
{ {
/* the number of pids in table */ /* the number of pids in table */
int pidn; int pidn;
@ -901,19 +894,19 @@ l_configure(lua_State *L)
static const luaL_reg lsyncdlib[] = { static const luaL_reg lsyncdlib[] = {
{"add_watch", l_add_watch }, {"add_watch", l_add_watch },
{"addto_clock", l_addto_clock }, {"addtoclock", l_addtoclock },
{"is_before_eq", l_is_before_eq }, {"clockbeforeq", l_clockbeforeq },
{"configure", l_configure }, {"configure", l_configure },
{"earlier", l_earlier }, {"earlier", l_earlier },
{"exec", l_exec }, {"exec", l_exec },
{"log", l_log }, {"log", l_log },
{"now", l_now }, {"now", l_now },
{"writefd", l_writefd }, {"writefd", l_writefd },
{"real_dir", l_real_dir }, {"realdir", l_realdir },
{"stackdump", l_stackdump }, {"stackdump", l_stackdump },
{"sub_dirs", l_sub_dirs }, {"subdirs", l_subdirs },
{"terminate", l_terminate }, {"terminate", l_terminate },
{"wait_pids", l_wait_pids }, {"waitpids", l_waitpids },
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -138,37 +138,37 @@ local CountArray = (function()
return {new = new} return {new = new}
end)() end)()
-----
-- Metatable to limit keys to those only presented in their prototype
-- --
local meta_check_prototype = { -------
__index = function(t, k) ---- Metatable to limit keys to those only presented in their prototype
if not t.prototype[k] then ----
error("tables prototype doesn't have key '"..k.."'.", 2) --local meta_check_prototype = {
end -- __index = function(t, k)
return rawget(t, k) -- if not t.prototype[k] then
end, -- error("tables prototype doesn't have key '"..k.."'.", 2)
__newindex = function(t, k, v) -- end
if not t.prototype[k] then -- return rawget(t, k)
error("tables prototype doesn't have key '"..k.."'.", 2) -- end,
end -- __newindex = function(t, k, v)
rawset(t, k, v) -- if not t.prototype[k] then
end -- error("tables prototype doesn't have key '"..k.."'.", 2)
} -- end
-- rawset(t, k, v)
----- -- end
-- Sets the prototype of a table limiting its keys to a defined list. --}
-- --
local function set_prototype(t, prototype) -------
t.prototype = prototype ---- Sets the prototype of a table limiting its keys to a defined list.
for k, _ in pairs(t) do ----
if not t.prototype[k] and k ~= "prototype" then --local function set_prototype(t, prototype)
error("Cannot set prototype, conflicting key: '"..k.."'.", 2) -- t.prototype = prototype
end -- for k, _ in pairs(t) do
end -- if not t.prototype[k] and k ~= "prototype" then
setmetatable(t, meta_check_prototype) -- error("Cannot set prototype, conflicting key: '"..k.."'.", 2)
end -- end
-- end
-- setmetatable(t, meta_check_prototype)
--end
---- ----
-- Locks globals, -- Locks globals,
@ -263,7 +263,7 @@ function Sync.delay(self, ename, time, pathname, pathname2)
local alarm local alarm
-- TODO scope -- TODO scope
if time and self.config.delay then if time and self.config.delay then
alarm = lsyncd.addto_clock(time, self.config.delay) alarm = lsyncd.addtoclock(time, self.config.delay)
else else
alarm = lsyncd.now() alarm = lsyncd.now()
end end
@ -362,7 +362,7 @@ local Syncs = (function()
require_opt("source") require_opt("source")
-- absolute path of source -- absolute path of source
local real_src = lsyncd.real_dir(config.source) local real_src = lsyncd.realdir(config.source)
if not real_src then if not real_src then
log(Error, "Cannot access source directory: ", config.source) log(Error, "Cannot access source directory: ", config.source)
terminate(-1) -- ERRNO terminate(-1) -- ERRNO
@ -454,7 +454,7 @@ local Inotifies = (function()
-- registers and adds watches for all subdirectories -- registers and adds watches for all subdirectories
if recurse then if recurse then
local subdirs = lsyncd.sub_dirs(root .. path) local subdirs = lsyncd.subdirs(root .. path)
for _, dirname in ipairs(subdirs) do for _, dirname in ipairs(subdirs) do
add(root, path..dirname.."/", true, sync) add(root, path..dirname.."/", true, sync)
end end
@ -733,15 +733,15 @@ local StatusFile = (function()
-- some logic to not write too often -- some logic to not write too often
if settings.statusIntervall > 0 then if settings.statusIntervall > 0 then
-- already waiting -- already waiting
if alarm and lsyncd.is_before_eq(now, alarm) then if alarm and lsyncd.clockbeforeq(now, alarm) then
log("Statusfile", "waiting(",now," < ",alarm,")") log("Statusfile", "waiting(",now," < ",alarm,")")
return return
end end
-- determines when a next write will be possible -- determines when a next write will be possible
if not alarm then if not alarm then
local nextWrite = lastWritten and local nextWrite = lastWritten and
lsyncd.addto_clock(now, settings.statusIntervall) lsyncd.addtoclock(now, settings.statusIntervall)
if nextWrite and lsyncd.is_before_eq(now, nextWrite) then if nextWrite and lsyncd.clockbeforeq(now, nextWrite) then
log("Statusfile", "setting alarm: ", nextWrite) log("Statusfile", "setting alarm: ", nextWrite)
alarm = nextWrite alarm = nextWrite
return return
@ -787,7 +787,7 @@ function lsyncd_cycle(now)
if s.processes:size() < s.config.maxProcesses then if s.processes:size() < s.config.maxProcesses then
local delays = s.delays local delays = s.delays
local d = delays[1] local d = delays[1]
if d and lsyncd.is_before_eq(d.alarm, now) then if d and lsyncd.clockbeforeq(d.alarm, now) then
invoke_action(s, d) invoke_action(s, d)
table.remove(delays, 1) table.remove(delays, 1)
s.delayname[d.pathname] = nil -- TODO grab from stack s.delayname[d.pathname] = nil -- TODO grab from stack
@ -922,7 +922,7 @@ function lsyncd_initialize()
table.insert(pids, pid) table.insert(pids, pid)
end end
end end
lsyncd.wait_pids(pids, "startup_collector") lsyncd.waitpids(pids, "startup_collector")
log("Normal", "- Entering normal operation with ", log("Normal", "- Entering normal operation with ",
Inotifies.size(), " monitored directories -") Inotifies.size(), " monitored directories -")
else else
@ -1020,7 +1020,7 @@ end
----- -----
-- lsyncd classic - sync with rsync -- lsyncd classic - sync with rsync
-- --
local default_rsync = { local defaultRsync = {
---- ----
-- Called for every sync/target pair on startup -- Called for every sync/target pair on startup
startup = function(source, target) startup = function(source, target)
@ -1076,7 +1076,6 @@ default = {
Delete = { Attrib = "Delete", Modify = "Delete", Create = "Modify", Delete = "Delete" }, Delete = { Attrib = "Delete", Modify = "Delete", Create = "Modify", Delete = "Delete" },
}, },
rsync = default_rsync rsync = defaultRsync
} }