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

View File

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