mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-08 17:24:06 +00:00
removed enum
This commit is contained in:
parent
20cadd6a5d
commit
83aed80aa7
35
inotify.c
35
inotify.c
@ -39,6 +39,15 @@
|
|||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Event types.
|
||||||
|
*/
|
||||||
|
const char * ATTRIB = "Attrib";
|
||||||
|
const char * MODIFY = "Modify";
|
||||||
|
const char * CREATE = "Create";
|
||||||
|
const char * DELETE = "Delete";
|
||||||
|
const char * MOVE = "Move";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The inotify file descriptor.
|
* The inotify file descriptor.
|
||||||
*/
|
*/
|
||||||
@ -63,6 +72,7 @@ l_addwatch(lua_State *L)
|
|||||||
{
|
{
|
||||||
const char *path = luaL_checkstring(L, 1);
|
const char *path = luaL_checkstring(L, 1);
|
||||||
lua_Integer wd = inotify_add_watch(inotify_fd, path, standard_event_mask);
|
lua_Integer wd = inotify_add_watch(inotify_fd, path, standard_event_mask);
|
||||||
|
printlogf(L, "Inotify", "addwatch(%s)->%d", path, wd);
|
||||||
lua_pushinteger(L, wd);
|
lua_pushinteger(L, wd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -78,6 +88,7 @@ l_rmwatch(lua_State *L)
|
|||||||
{
|
{
|
||||||
lua_Integer wd = luaL_checkinteger(L, 1);
|
lua_Integer wd = luaL_checkinteger(L, 1);
|
||||||
inotify_rm_watch(inotify_fd, wd);
|
inotify_rm_watch(inotify_fd, wd);
|
||||||
|
printlogf(L, "Inotify", "rmwatch()<-%d", wd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +124,7 @@ static void
|
|||||||
handle_event(lua_State *L,
|
handle_event(lua_State *L,
|
||||||
struct inotify_event *event)
|
struct inotify_event *event)
|
||||||
{
|
{
|
||||||
int event_type;
|
const char *event_type = NULL;
|
||||||
|
|
||||||
/* 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;
|
||||||
@ -141,22 +152,23 @@ handle_event(lua_State *L,
|
|||||||
/* a buffered MOVE_FROM is not followed by anything,
|
/* a buffered MOVE_FROM is not followed by anything,
|
||||||
thus it is unary */
|
thus it is unary */
|
||||||
event = move_event_buf;
|
event = move_event_buf;
|
||||||
event_type = DELETE;
|
event_type = "Delete";
|
||||||
move_event = false;
|
move_event = false;
|
||||||
} else if (move_event &&
|
} else if (move_event &&
|
||||||
( !(IN_MOVED_TO & event->mask) ||
|
( !(IN_MOVED_TO & event->mask) ||
|
||||||
event->cookie != move_event_buf->cookie) ) {
|
event->cookie != move_event_buf->cookie) ) {
|
||||||
/* there is a MOVE_FROM event in the buffer and this is not the match
|
/* there is a MOVE_FROM event in the buffer and this is not the match
|
||||||
* continue in this function iteration to handle the buffer instead */
|
* continue in this function iteration to handle the buffer instead */
|
||||||
|
logstring("Inotify", "icore, changing unary MOVE_FROM into DELETE")
|
||||||
after_buf = event;
|
after_buf = event;
|
||||||
event = move_event_buf;
|
event = move_event_buf;
|
||||||
event_type = DELETE;
|
event_type = "Delete";
|
||||||
move_event = false;
|
move_event = false;
|
||||||
} else if ( move_event &&
|
} else if ( move_event &&
|
||||||
(IN_MOVED_TO & event->mask) &&
|
(IN_MOVED_TO & event->mask) &&
|
||||||
event->cookie == move_event_buf->cookie ) {
|
event->cookie == move_event_buf->cookie ) {
|
||||||
/* this is indeed a matched move */
|
/* this is indeed a matched move */
|
||||||
event_type = MOVE;
|
event_type = "Move";
|
||||||
move_event = false;
|
move_event = false;
|
||||||
} else if (IN_MOVED_FROM & event->mask) {
|
} else if (IN_MOVED_FROM & event->mask) {
|
||||||
/* just the MOVE_FROM, buffers this event, and wait if next event is
|
/* just the MOVE_FROM, buffers this event, and wait if next event is
|
||||||
@ -189,22 +201,17 @@ handle_event(lua_State *L,
|
|||||||
/* rm'ed */
|
/* rm'ed */
|
||||||
event_type = DELETE;
|
event_type = DELETE;
|
||||||
} else {
|
} else {
|
||||||
logstring("Inotify", "skipped some inotify event.");
|
logstring("Inotify", "icore, skipped some inotify event.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and hands over to runner */
|
/* and hands over to runner */
|
||||||
load_runner_func(L, "inotifyEvent");
|
load_runner_func(L, "inotifyEvent");
|
||||||
switch(event_type) {
|
if (!event_type) {
|
||||||
case ATTRIB : lua_pushstring(L, "Attrib"); break;
|
|
||||||
case MODIFY : lua_pushstring(L, "Modify"); break;
|
|
||||||
case CREATE : lua_pushstring(L, "Create"); break;
|
|
||||||
case DELETE : lua_pushstring(L, "Delete"); break;
|
|
||||||
case MOVE : lua_pushstring(L, "Move"); break;
|
|
||||||
default :
|
|
||||||
logstring("Error", "Internal: unknown event in handle_event()");
|
logstring("Error", "Internal: unknown event in handle_event()");
|
||||||
exit(-1); // ERRNO
|
exit(-1); // ERRNO
|
||||||
}
|
}
|
||||||
|
lua_pushstring(L, event_type);
|
||||||
if (event_type != MOVE) {
|
if (event_type != MOVE) {
|
||||||
lua_pushnumber(L, event->wd);
|
lua_pushnumber(L, event->wd);
|
||||||
} else {
|
} else {
|
||||||
@ -228,7 +235,7 @@ handle_event(lua_State *L,
|
|||||||
|
|
||||||
/* if there is a buffered event executes it */
|
/* if there is a buffered event executes it */
|
||||||
if (after_buf) {
|
if (after_buf) {
|
||||||
logstring("Inotify", "handling buffered event.");
|
logstring("Inotify", "icore, handling buffered event.");
|
||||||
handle_event(L, after_buf);
|
handle_event(L, after_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,7 +302,7 @@ inotify_ready(lua_State *L, int fd, void *extra)
|
|||||||
|
|
||||||
/* 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) {
|
||||||
logstring("Inotify", "handling unary move from.");
|
logstring("Inotify", "icore, handling unary move from.");
|
||||||
handle_event(L, NULL);
|
handle_event(L, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
lsyncd.h
12
lsyncd.h
@ -50,18 +50,6 @@ extern struct settings {
|
|||||||
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
|
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
|
||||||
#define time_before_eq(a,b) time_after_eq(b,a)
|
#define time_before_eq(a,b) time_after_eq(b,a)
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
|
||||||
* Event types.
|
|
||||||
* TODO, needed here?
|
|
||||||
*/
|
|
||||||
enum event_type {
|
|
||||||
NONE = 0,
|
|
||||||
ATTRIB = 1,
|
|
||||||
MODIFY = 2,
|
|
||||||
CREATE = 3,
|
|
||||||
DELETE = 4,
|
|
||||||
MOVE = 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* pushes a runner function and the runner error handler onto Lua stack */
|
/* pushes a runner function and the runner error handler onto Lua stack */
|
||||||
extern void load_runner_func(lua_State *L, const char *name);
|
extern void load_runner_func(lua_State *L, const char *name);
|
||||||
|
@ -1593,9 +1593,9 @@ local Inotifies = (function()
|
|||||||
|
|
||||||
if filename2 then
|
if filename2 then
|
||||||
log("Inotify", "got event ",etype," ",filename,
|
log("Inotify", "got event ",etype," ",filename,
|
||||||
" to ", filename2)
|
"(",wd,") to ",filename2,"(",wd2,")")
|
||||||
else
|
else
|
||||||
log("Inotify", "got event ", etype, " ", filename)
|
log("Inotify","got event ",etype," ",filename,"(",wd,")")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- looks up the watch descriptor id
|
-- looks up the watch descriptor id
|
||||||
|
@ -16,7 +16,8 @@ local trgdir = tdir.."trg/"
|
|||||||
|
|
||||||
posix.mkdir(srcdir)
|
posix.mkdir(srcdir)
|
||||||
posix.mkdir(trgdir)
|
posix.mkdir(trgdir)
|
||||||
local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,"-log","all")
|
local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,
|
||||||
|
"-log","Inotify","-log","Exec")
|
||||||
|
|
||||||
cwriteln("waiting for Lsyncd to startup")
|
cwriteln("waiting for Lsyncd to startup")
|
||||||
posix.sleep(1)
|
posix.sleep(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user