mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 14:43:09 +00:00
This commit is contained in:
parent
455a9941fa
commit
83d0f90c65
43
lsyncd.c
43
lsyncd.c
@ -546,9 +546,10 @@ l_now(lua_State *L)
|
|||||||
/**
|
/**
|
||||||
* Returns (on Lua stack) the addition of a clock timer by seconds.
|
* Returns (on Lua stack) the addition of a clock timer by seconds.
|
||||||
*
|
*
|
||||||
* @param1 the clock timer
|
* @param1 (Lua stack) the clock timer
|
||||||
* @param2 seconds to change clock.
|
* @param2 (Lua stack) seconds to change clock.
|
||||||
* TODO
|
*
|
||||||
|
* @return (Lua stack) clock timer + seconds.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
l_addtoclock(lua_State *L)
|
l_addtoclock(lua_State *L)
|
||||||
@ -565,6 +566,7 @@ l_addtoclock(lua_State *L)
|
|||||||
*
|
*
|
||||||
* @param (Lua stack) Path to binary to call
|
* @param (Lua stack) Path to binary to call
|
||||||
* @params (Lua stack) list of string as arguments
|
* @params (Lua stack) list of string as arguments
|
||||||
|
*
|
||||||
* @return (Lua stack) the pid on success, 0 on failure.
|
* @return (Lua stack) the pid on success, 0 on failure.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
@ -893,9 +895,10 @@ bool move_event = false;
|
|||||||
* Handles an inotify event.
|
* Handles an inotify event.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
handle_event(lua_State *L, struct inotify_event *event) {
|
handle_event(lua_State *L,
|
||||||
/* TODO */
|
struct inotify_event *event)
|
||||||
int event_type = NONE;
|
{
|
||||||
|
int event_type;
|
||||||
|
|
||||||
/* used to execute two events in case of unmatched MOVE_FROM buffer */
|
/* used to execute two events in case of unmatched MOVE_FROM buffer */
|
||||||
struct inotify_event *after_buf = NULL;
|
struct inotify_event *after_buf = NULL;
|
||||||
@ -1159,10 +1162,27 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* load Lua */
|
/* load Lua */
|
||||||
L = lua_open();
|
L = lua_open();
|
||||||
|
luaL_openlibs(L);
|
||||||
|
{
|
||||||
|
/* checks the lua version */
|
||||||
|
const char *version;
|
||||||
|
int major, minor;
|
||||||
|
lua_getglobal(L, "_VERSION");
|
||||||
|
version = luaL_checkstring(L, -1);
|
||||||
|
if (sscanf(version, "Lua %d.%d", &major, &minor) != 2) {
|
||||||
|
fprintf(stderr, "cannot parse lua library version!\n");
|
||||||
|
return -1; // ERRNO
|
||||||
|
}
|
||||||
|
if ((major < 5) || (major == 5 && minor < 1)) {
|
||||||
|
fprintf(stderr, "lua library is too old. Need 5.1 at least");
|
||||||
|
return -1; // ERRNO
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
/* prepares logging early */
|
||||||
int i = 1;
|
int i = 1;
|
||||||
/* Prepares logging early */
|
|
||||||
add_logcat("Normal", LOG_NOTICE);
|
add_logcat("Normal", LOG_NOTICE);
|
||||||
add_logcat("Error", LOG_ERR);
|
add_logcat("Error", LOG_ERR);
|
||||||
while (i < argc) {
|
while (i < argc) {
|
||||||
@ -1180,8 +1200,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO check lua version */
|
/* registers lsycnd core */
|
||||||
luaL_openlibs(L);
|
|
||||||
luaL_register(L, "lsyncd", lsyncdlib);
|
luaL_register(L, "lsyncd", lsyncdlib);
|
||||||
lua_setglobal(L, "lysncd");
|
lua_setglobal(L, "lysncd");
|
||||||
|
|
||||||
@ -1278,7 +1297,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* checks version match between runner/core */
|
/* asserts version match between runner and core */
|
||||||
const char *lversion;
|
const char *lversion;
|
||||||
lua_getglobal(L, "lsyncd_version");
|
lua_getglobal(L, "lsyncd_version");
|
||||||
lversion = luaL_checkstring(L, -1);
|
lversion = luaL_checkstring(L, -1);
|
||||||
@ -1308,7 +1327,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* start the option parser in lua script */
|
/* starts the option parser in lua script */
|
||||||
int idx = 1;
|
int idx = 1;
|
||||||
const char *s;
|
const char *s;
|
||||||
/* creates a table with all remaining argv option arguments */
|
/* creates a table with all remaining argv option arguments */
|
||||||
@ -1326,7 +1345,7 @@ main(int argc, char *argv[])
|
|||||||
if (s) {
|
if (s) {
|
||||||
lsyncd_config_file = s_strdup(s);
|
lsyncd_config_file = s_strdup(s);
|
||||||
}
|
}
|
||||||
lua_pop(L, 2); // TODO
|
lua_pop(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsyncd_config_file) {
|
if (lsyncd_config_file) {
|
||||||
|
41
lsyncd.lua
41
lsyncd.lua
@ -176,7 +176,8 @@ local Delay = (function()
|
|||||||
-----
|
-----
|
||||||
-- Creates a new delay.
|
-- Creates a new delay.
|
||||||
--
|
--
|
||||||
-- @param TODO
|
-- @params see below
|
||||||
|
--
|
||||||
local function new(etype, alarm, path, path2)
|
local function new(etype, alarm, path, path2)
|
||||||
local o = {
|
local o = {
|
||||||
-----
|
-----
|
||||||
@ -445,7 +446,7 @@ local Inlet, InletControl = (function()
|
|||||||
--
|
--
|
||||||
local function cancelEvent(event)
|
local function cancelEvent(event)
|
||||||
local delay = event[delayKey]
|
local delay = event[delayKey]
|
||||||
if delay.status ~= "waiting" then
|
if delay.status ~= "wait" then
|
||||||
log("Error", "Ignored try to cancel a non-waiting event of type ",
|
log("Error", "Ignored try to cancel a non-waiting event of type ",
|
||||||
event.etype)
|
event.etype)
|
||||||
return
|
return
|
||||||
@ -655,9 +656,15 @@ local Sync = (function()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.delays[1] then
|
-- finds the nearest delay waiting to be spawned
|
||||||
return self.delays[1].alarm
|
for _, d in ipairs(self.delays) do
|
||||||
|
if d.status == "wait" then
|
||||||
|
return d.alarm
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- nothing to spawn.
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -1119,10 +1126,13 @@ end)()
|
|||||||
--============================================================================
|
--============================================================================
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- true after runner.initalized()
|
-- Current status of lsyncd.
|
||||||
-- TODO change to string X2
|
|
||||||
--
|
--
|
||||||
local running = false
|
-- "init" ... on (re)init
|
||||||
|
-- "run" ... normal operation
|
||||||
|
-- "fade" ... waits for remaining processes
|
||||||
|
--
|
||||||
|
local lsyncdStatus = "init"
|
||||||
|
|
||||||
----
|
----
|
||||||
-- the cores interface to the runner
|
-- the cores interface to the runner
|
||||||
@ -1284,7 +1294,7 @@ function runner.initialize()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- from now on use logging as configured instead of stdout/err.
|
-- from now on use logging as configured instead of stdout/err.
|
||||||
running = true;
|
lsyncdStatus = "run";
|
||||||
lsyncd.configure("running");
|
lsyncd.configure("running");
|
||||||
|
|
||||||
-- runs through the syncs table filled by user calling directory()
|
-- runs through the syncs table filled by user calling directory()
|
||||||
@ -1372,8 +1382,8 @@ end
|
|||||||
-- Main utility to create new observations.
|
-- Main utility to create new observations.
|
||||||
--
|
--
|
||||||
function sync(opts)
|
function sync(opts)
|
||||||
if running then
|
if lsyncdStatus ~= "init" then
|
||||||
error("Cannot add new syncs while running!")
|
error("Sync can only be created on initialization.", 2)
|
||||||
end
|
end
|
||||||
Syncs.add(opts)
|
Syncs.add(opts)
|
||||||
end
|
end
|
||||||
@ -1456,9 +1466,9 @@ local defaultRsync = {
|
|||||||
-- TODO make readonly
|
-- TODO make readonly
|
||||||
--
|
--
|
||||||
default = {
|
default = {
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Default action
|
-- Default action calls user scripts on**** functions.
|
||||||
-- TODO desc
|
|
||||||
--
|
--
|
||||||
action = function(inlet)
|
action = function(inlet)
|
||||||
-- in case of moves getEvent returns the origin and dest of the move
|
-- in case of moves getEvent returns the origin and dest of the move
|
||||||
@ -1471,7 +1481,10 @@ default = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Called if to see if two events can be collapsed
|
-- Called to see if two events can be collapsed.
|
||||||
|
--
|
||||||
|
-- Default function uses the collapseTable.
|
||||||
|
--
|
||||||
-- @param event1 first event
|
-- @param event1 first event
|
||||||
-- @param event2 second event
|
-- @param event2 second event
|
||||||
-- @return -1 ... no interconnection
|
-- @return -1 ... no interconnection
|
||||||
@ -1541,7 +1554,7 @@ default = {
|
|||||||
if type(config.onStartup) == "function" then
|
if type(config.onStartup) == "function" then
|
||||||
local event = inlet.createBlanketEvent()
|
local event = inlet.createBlanketEvent()
|
||||||
local startup = config.onStartup(event)
|
local startup = config.onStartup(event)
|
||||||
if event.status == "waiting" then
|
if event.status == "wait" then
|
||||||
-- user script did not spawn anything
|
-- user script did not spawn anything
|
||||||
-- thus the blanket event is deleted again.
|
-- thus the blanket event is deleted again.
|
||||||
inlet.cancelEvent(event)
|
inlet.cancelEvent(event)
|
||||||
|
Loading…
Reference in New Issue
Block a user