mirror of https://github.com/octoleo/lsyncd.git
This commit is contained in:
parent
7e32b9b298
commit
a636b31e9f
|
@ -14,19 +14,28 @@ print(bla)
|
||||||
------
|
------
|
||||||
-- for testing purposes
|
-- for testing purposes
|
||||||
--
|
--
|
||||||
slower = "sleep 10"
|
slower = "sleep 10 && "
|
||||||
slowbash = {
|
slowbash = {
|
||||||
startup = function(source, target)
|
startup = function(source, target)
|
||||||
log(NORMAL, "cp -r from "..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)
|
source, target)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
create = function(source, path, name, target)
|
create = function(source, path, name, target)
|
||||||
local src = source..path..name
|
local src = source..path..name
|
||||||
log(NORMAL, "create from "..source..path..name.." -> "..target..path..name)
|
local trg = target..path..name
|
||||||
return exec("/bin/bash", "-c", slower.."&& cp '$1' '$2'", "/bin/bash",
|
log(NORMAL, "create from "..src.." -> "..trg)
|
||||||
source..path..name, target..path..name)
|
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,
|
end,
|
||||||
|
|
||||||
attrib = function(source, path, name, target)
|
attrib = function(source, path, name, target)
|
||||||
|
@ -36,14 +45,15 @@ slowbash = {
|
||||||
|
|
||||||
delete = function(source, path, name, target)
|
delete = function(source, path, name, target)
|
||||||
log(NORMAL, "delete "..target..path..name)
|
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)
|
target..path..name)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
move = function(source, path, name, destpath, destname, target)
|
move = function(source, path, name, destpath, destname, target)
|
||||||
log(NORMAL, "move from " .. destination .. "/" .. path)
|
log(NORMAL, "move from " .. destination .. "/" .. path)
|
||||||
return exec("/bin/bash", "-c", "sleep " .. slowsec .. " && rm $1 $2", "/bin/bash",
|
-- return exec("/bin/bash", "-c", "sleep " .. slowsec .. " && rm $1 $2", "/bin/bash",
|
||||||
source .. "/" .. path, target .. "/" .. path)
|
-- source .. "/" .. path, target .. "/" .. path)
|
||||||
|
return 0
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +75,6 @@ rsync = {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
sync("s", "d", slowbash)
|
sync("s", "d/", slowbash)
|
||||||
|
|
||||||
|
|
||||||
|
|
9
lsyncd.c
9
lsyncd.c
|
@ -329,8 +329,7 @@ l_log(lua_State *L)
|
||||||
static int
|
static int
|
||||||
l_now(lua_State *L)
|
l_now(lua_State *L)
|
||||||
{
|
{
|
||||||
clock_t c = times(NULL);
|
lua_pushinteger(L, times(NULL));
|
||||||
lua_pushinteger(L, c);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,11 +902,15 @@ masterloop(lua_State *L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* checks if there is an unary MOVE_FROM left in the buffer */
|
/* checks if there is an unary MOVE_FROM left in the buffer */
|
||||||
if (move_event) {
|
if (move_event) {
|
||||||
handle_event(L, NULL);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
78
lsyncd.lua
78
lsyncd.lua
|
@ -50,7 +50,7 @@ local origins = {}
|
||||||
-- .delays = [#) { .. the delays stack
|
-- .delays = [#) { .. the delays stack
|
||||||
-- .atype .. enum, kind of action
|
-- .atype .. enum, kind of action
|
||||||
-- .wd .. watch descriptor id this origins from TODO needed?
|
-- .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)
|
-- .filename .. filename or nil (=dir itself)
|
||||||
-- (.movepeer) .. for MOVEFROM/MOVETO link to other delay
|
-- (.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 delays = target.delays
|
||||||
local nd = {atype = atype,
|
local nd = {atype = atype,
|
||||||
wd = wd,
|
wd = wd,
|
||||||
sync = sync,
|
sync = sync,
|
||||||
filename = filename }
|
filename = filename }
|
||||||
if time ~= nil and origin.actions.delay ~= nil then
|
if time ~= nil and origin.actions.delay ~= nil then
|
||||||
nd.alarm = lsyncd.append_time(time, origin.actions.delay)
|
nd.alarm = lsyncd.append_time(time, origin.actions.delay)
|
||||||
end
|
end
|
||||||
|
@ -152,10 +152,76 @@ local function attend_dir(origin, path, parent)
|
||||||
end
|
end
|
||||||
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
|
-- Called from core everytime at the latest of an
|
||||||
function lsyncd_alarm()
|
-- expired alarm (or more often)
|
||||||
-- TODO
|
--
|
||||||
|
-- @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
|
end
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
Loading…
Reference in New Issue