From a636b31e9f9b7df4bbcc7b20af7987ef0af95cb3 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Sat, 23 Oct 2010 12:36:55 +0000 Subject: [PATCH] --- lsyncd-conf.lua | 28 ++++++++++++------ lsyncd.c | 9 ++++-- lsyncd.lua | 78 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 97 insertions(+), 18 deletions(-) diff --git a/lsyncd-conf.lua b/lsyncd-conf.lua index 700a8c0..bd53216 100644 --- a/lsyncd-conf.lua +++ b/lsyncd-conf.lua @@ -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) diff --git a/lsyncd.c b/lsyncd.c index 9a91275..de03b97 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -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); } } diff --git a/lsyncd.lua b/lsyncd.lua index 10cd9a4..bc90527 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -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 ----