This commit is contained in:
Axel Kittenberger 2010-10-23 12:36:55 +00:00
parent 7e32b9b298
commit a636b31e9f
3 changed files with 97 additions and 18 deletions

View File

@ -14,19 +14,28 @@ print(bla)
------
-- for testing purposes
--
slower = "sleep 10"
slower = "sleep 10 && "
slowbash = {
startup = function(source, target)
log(NORMAL, "cp -r from "..source.." -> "..target)
return exec("/bin/bash", "-c", "cp -r \"$1\" \"$2\"", "/bin/bash",
return exec("/bin/bash", "-c", "cp -r \"$1\"* \"$2\"", "/bin/bash",
source, target)
end,
create = function(source, path, name, target)
local src = source..path..name
log(NORMAL, "create from "..source..path..name.." -> "..target..path..name)
return exec("/bin/bash", "-c", slower.."&& cp '$1' '$2'", "/bin/bash",
source..path..name, target..path..name)
local trg = target..path..name
log(NORMAL, "create from "..src.." -> "..trg)
return exec("/bin/bash", "-c", slower.."cp \"$1\" \"$2\"", "/bin/bash",
src, trg)
end,
modify = function(source, path, name, target)
local src = source..path..name
local trg = target..path..name
log(NORMAL, "modify from "..src.." -> "..trg)
return exec("/bin/bash", "-c", slower.."cp \"$1\" \"$2\"", "/bin/bash",
src, trg)
end,
attrib = function(source, path, name, target)
@ -36,14 +45,15 @@ slowbash = {
delete = function(source, path, name, target)
log(NORMAL, "delete "..target..path..name)
return exec("/bin/bash", "-c", slower.." && rm $1", "/bin/bash",
return exec("/bin/bash", "-c", slower.."rm \"$1\"", "/bin/bash",
target..path..name)
end,
move = function(source, path, name, destpath, destname, target)
log(NORMAL, "move from " .. destination .. "/" .. path)
return exec("/bin/bash", "-c", "sleep " .. slowsec .. " && rm $1 $2", "/bin/bash",
source .. "/" .. path, target .. "/" .. path)
-- return exec("/bin/bash", "-c", "sleep " .. slowsec .. " && rm $1 $2", "/bin/bash",
-- source .. "/" .. path, target .. "/" .. path)
return 0
end,
}
@ -65,6 +75,6 @@ rsync = {
end
}
sync("s", "d", slowbash)
sync("s", "d/", slowbash)

View File

@ -329,8 +329,7 @@ l_log(lua_State *L)
static int
l_now(lua_State *L)
{
clock_t c = times(NULL);
lua_pushinteger(L, c);
lua_pushinteger(L, times(NULL));
return 1;
}
@ -903,11 +902,15 @@ masterloop(lua_State *L)
}
}
}
/* checks if there is an unary MOVE_FROM left in the buffer */
if (move_event) {
handle_event(L, NULL);
}
/* let the runner spawn child processes */
lua_getglobal(L, "lsyncd_alarm");
lua_pushinteger(L, times(NULL));
lua_call(L, 1, 0);
}
}

View File

@ -50,7 +50,7 @@ local origins = {}
-- .delays = [#) { .. the delays stack
-- .atype .. enum, kind of action
-- .wd .. watch descriptor id this origins from TODO needed?
-- .attend .. link to atttender that raised this delay.
-- .sync .. link to sync that raised this delay.
-- .filename .. filename or nil (=dir itself)
-- (.movepeer) .. for MOVEFROM/MOVETO link to other delay
-- }
@ -106,8 +106,8 @@ local function delay_action(atype, wd, sync, filename, time)
local delays = target.delays
local nd = {atype = atype,
wd = wd,
sync = sync,
filename = filename }
sync = sync,
filename = filename }
if time ~= nil and origin.actions.delay ~= nil then
nd.alarm = lsyncd.append_time(time, origin.actions.delay)
end
@ -152,10 +152,76 @@ local function attend_dir(origin, path, parent)
end
end
-----
-- TODO
--
--
local function invoke_action(target, delay)
-- .origin .. link to origin
-- .path .. relative path of dir
-- .parent .. link to parent directory in watches
-- or nil for origin
local sync = delay.sync
local origin = sync.origin
local actions = origin.actions
local func = nil
if delay.atype == CREATE then
if actions.create ~= nil then
func = actions.create
elseif actions.default ~= nil then
func = actions.default
end
elseif delay.atype == ATTRIB then
if actions.attrib ~= nil then
func = actions.attrib
elseif actions.default ~= nil then
func = actions.default
end
elseif delay.atype == MODIFY then
if actions.modify ~= nil then
func = actions.modify
elseif actions.default ~= nil then
func = actions.default
end
elseif delay.atype == DELETE then
if actions.delete ~= nil then
func = actions.delete
elseif actions.default ~= nil then
func = actions.default
end
elseif delay.atype == MOVE then
log(ERROR, "MOVE NOT YET IMPLEMENTED!")
end
if func ~= nil then
pid = func(origin.source, sync.path, delay.filename, target.ident)
end
end
-- .delays = [#) { .. the delays stack
-- .atype .. enum, kind of action
-- .wd .. watch descriptor id this origins from TODO needed?
-- .attend .. link to atttender that raised this delay.
-- .filename .. filename or nil (=dir itself)
-- (.movepeer) .. for MOVEFROM/MOVETO link to other delay
----
-- Called from core everytime after
function lsyncd_alarm()
-- TODO
-- Called from core everytime at the latest of an
-- expired alarm (or more often)
--
-- @param now the time is now
--
function lsyncd_alarm(now)
for i, target in ipairs(targets) do
local delays = target.delays
if delays[1] ~= nil then
invoke_action(target, target.delays[1])
table.remove(delays, 1)
end
end
end
----