From 306d117959b7bbf686eca2470c2f422388f4b1fa Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Sat, 20 Nov 2010 14:21:55 +0000 Subject: [PATCH] fixing masterloop --- lsyncd.c | 11 ++++++++++- lsyncd.lua | 37 +++++++++++++++++++++---------------- tests/randrsync.lua | 3 ++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/lsyncd.c b/lsyncd.c index 44fcb60..b794570 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -905,7 +905,7 @@ l_stackdump(lua_State* L) /** * Reads the directories entries. - * XXX + * * @param (Lua stack) absolute path to directory. * @return (Lua stack) a table of directory names. * names are keys, values are boolean @@ -1332,6 +1332,15 @@ masterloop(lua_State *L) /* nothing more inotify */ break; } + if (len < 0) { + if (errno == EAGAIN) { + /* nothing more inotify */ + break; + } else { + printlogf(L, "Error", "Read fail on inotify"); + exit(-1); // ERRNO + } + } while (i < len && !hup && !term) { struct inotify_event *event = (struct inotify_event *) &readbuf[i]; diff --git a/lsyncd.lua b/lsyncd.lua index 07cf0b0..e243bcc 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -1475,22 +1475,27 @@ local Inotifies = (function() -- registers and adds watches for all subdirectories -- and/or raises create events for all entries - if recurse or raise then - local entries = lsyncd.readdir(path) - for dirname, isdir in pairs(entries) do - local pd = path .. dirname - if isdir then - pd = pd .. "/" - end + if not recurse and not raise then + return + end + + local entries = lsyncd.readdir(path) + if not entries then + return + end + for dirname, isdir in pairs(entries) do + local pd = path .. dirname + if isdir then + pd = pd .. "/" + end - -- creates a Create event for entry. - if raiseSync then - raiseSync:delay("Create", raiseTime, pd, nil) - end - -- adds syncs for subdirs - if isdir and recurse then - addWatch(pd, true, raiseSync, raiseTime) - end + -- creates a Create event for entry. + if raiseSync then + raiseSync:delay("Create", raiseTime, pd, nil) + end + -- adds syncs for subdirs + if isdir and recurse then + addWatch(pd, true, raiseSync, raiseTime) end end end @@ -1505,7 +1510,7 @@ local Inotifies = (function() end lsyncd.inotifyrm(wd) wdpaths[wd] = nil - pathwids[path] = nil + pathwds[path] = nil end ----- diff --git a/tests/randrsync.lua b/tests/randrsync.lua index 4d6f37a..206c8a6 100755 --- a/tests/randrsync.lua +++ b/tests/randrsync.lua @@ -16,7 +16,8 @@ local trgdir = tdir.."trg/" posix.mkdir(srcdir) posix.mkdir(trgdir) -local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir) +--local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,"-log", "all") +local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,"-log","all") cwriteln("waiting for Lsyncd to startup") posix.sleep(1)