From 52ebb96641416846e6847e1df2353898b03620bb Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Fri, 10 Dec 2010 15:30:45 +0000 Subject: [PATCH] working fsevents\! --- fsevents.c | 7 +++---- lsyncd.lua | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/fsevents.c b/fsevents.c index fc9a19a..840518a 100644 --- a/fsevents.c +++ b/fsevents.c @@ -299,19 +299,18 @@ fsevents_ready(lua_State *L, struct observance *obs) logstring("Error", "Internal, fsevents_fd != ob->fd"); exit(-1); // ERRNO } - while(true) { + { ptrdiff_t len; int err; len = read (fsevents_fd, readbuf, readbuf_size); err = errno; if (len == 0) { - /* nothing more */ - break; + return; } if (len < 0) { if (err == EAGAIN) { /* nothing more */ - break; + return; } else { printlogf(L, "Error", "Read fail on fsevents"); exit(-1); // ERRNO diff --git a/lsyncd.lua b/lsyncd.lua index b343542..1e63ddf 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -1770,10 +1770,7 @@ local Inotify = (function() -- @param filename2 -- local function event(etype, wd, isdir, time, filename, wd2, filename2) - local ftype; - if isdir then - ftype = "directory" filename = filename .. "/" if filename2 then filename2 = filename2 .. "/" @@ -1893,7 +1890,6 @@ local Fsevents = (function() if syncRoots[sync] then error("duplicate sync in Fanotify.addSync()") end - -- TODO for non subdirs adddir only syncRoots[sync] = dir end @@ -1907,8 +1903,36 @@ local Fsevents = (function() -- @param filename string filename without path -- @param filename2 -- - local function event(etype, isdir, time, filename, filename2) - log("Fsevents",etype,",",isdir,",",time,",",filename,",",filename2) + local function event(etype, isdir, time, path, path2) + log("Fsevents",etype,",",isdir,",",time,",",path,",",path2) + for _, s in Syncs.iwalk() do repeat + local root = s.source + if not path:starts(root) then + break -- continue + end + local relative = splitPath(path, root) + local relative2 + if path2 then + relative2 = splitPath(path2, root) + end + + -- makes a copy of etype to possibly change it + local etyped = etype + if etyped == 'Move' then + if not relative2 then + log("Normal", "Transformed Move to Create for ", + sync.config.name) + etyped = 'Create' + elseif not relative then + relative = relative2 + relative2 = nil + log("Normal", "Transformed Move to Delete for ", + sync.config.name) + etyped = 'Delete' + end + end + s:delay(etyped, time, relative, relative2) + until true end end -----