working on fsevents

This commit is contained in:
Axel Kittenberger 2010-12-09 15:12:08 +00:00
parent 44e0e45594
commit 9d449f5001

View File

@ -116,7 +116,7 @@ static const char *eventNames[FSE_MAX_EVENTS] = {
}; };
/* argument names*/ /* argument names*/
static const char *argNames[] = { /*static const char *argNames[] = {
"UNKNOWN", "UNKNOWN",
"VNODE", "VNODE",
"STRING", "STRING",
@ -130,7 +130,7 @@ static const char *argNames[] = {
"MODE", "MODE",
"GID", "GID",
"FINFO", "FINFO",
}; };*/
/** /**
* The read buffer * The read buffer
@ -148,8 +148,11 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
/* the len of the event */ /* the len of the event */
ssize_t len = sizeof(int32_t) + sizeof(pid_t); ssize_t len = sizeof(int32_t) + sizeof(pid_t);
bool want_path = false; bool expect_path = false;
bool expect_trg = false;
const char *path = NULL; const char *path = NULL;
const char *trg = NULL;
if (event->type == FSE_EVENTS_DROPPED) { if (event->type == FSE_EVENTS_DROPPED) {
logstring("Fsevents", "Events dropped!"); logstring("Fsevents", "Events dropped!");
@ -181,41 +184,49 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
} }
switch(atype) { switch(atype) {
case FSE_RENAME :
expect_trg = true;
/* fallthrough */
case FSE_CONTENT_MODIFIED :
case FSE_CREATE_FILE : case FSE_CREATE_FILE :
want_path = true; case FSE_CREATE_DIR :
case FSE_DELETE :
expect_path = true;
break; break;
} }
} }
{ {
/* assigns the expected arguments */
struct kfs_event_arg *arg = event->args; struct kfs_event_arg *arg = event->args;
while (len < mlen) { while (len < mlen) {
int eoff; int eoff;
if (arg->type == FSE_ARG_DONE) { if (arg->type == FSE_ARG_DONE) {
logstring("Fsevents", "argdone");
len += sizeof(u_int16_t); len += sizeof(u_int16_t);
break; break;
} }
switch (arg->type) { switch (arg->type) {
case FSE_ARG_STRING : case FSE_ARG_STRING :
if (want_path && !path) { if (expect_path && !path) {
path = arg->data.str; path = (char *)&arg->data.str;
} else if (expect_trg && path) {
trg = (char *)&arg->data.str;
} }
break; break;
} }
eoff = sizeof(arg->type) + sizeof(arg->len) + arg->len; eoff = sizeof(arg->type) + sizeof(arg->len) + arg->len;
len += eoff; len += eoff;
printlogf(L, "Fsevents", "arg:%s:%d",
argNames[arg->type > FSE_MAX_ARGS ? 0 : arg->type],
arg->len);
arg = (struct kfs_event_arg *) ((char *) arg + eoff); arg = (struct kfs_event_arg *) ((char *) arg + eoff);
} }
} }
if (path) { if (path) {
// printlogf(L, "path=%s", path); printlogf(L, "Fsevents", "path:%s", path);
}
if (trg) {
printlogf(L, "Fsevents", "trg:%s", trg);
} }
return len; return len;
} }