This commit is contained in:
Axel Kittenberger 2010-11-19 19:56:52 +00:00
parent c3b071d759
commit 1baed5c949
2 changed files with 34 additions and 10 deletions

View File

@ -1197,17 +1197,23 @@ handle_event(lua_State *L,
logstring("Error", "Internal: unknown event in handle_event()"); logstring("Error", "Internal: unknown event in handle_event()");
exit(-1); // ERRNO exit(-1); // ERRNO
} }
if (event_type != MOVE) {
lua_pushnumber(L, event->wd); lua_pushnumber(L, event->wd);
} else {
lua_pushnumber(L, move_event_buf->wd);
}
lua_pushboolean(L, (event->mask & IN_ISDIR) != 0); lua_pushboolean(L, (event->mask & IN_ISDIR) != 0);
lua_pushinteger(L, times(NULL)); lua_pushinteger(L, times(NULL));
if (event_type == MOVE) { if (event_type == MOVE) {
lua_pushstring(L, move_event_buf->name); lua_pushstring(L, move_event_buf->name);
lua_pushnumber(L, event->wd);
lua_pushstring(L, event->name); lua_pushstring(L, event->name);
} else { } else {
lua_pushstring(L, event->name); lua_pushstring(L, event->name);
lua_pushnil(L); lua_pushnil(L);
lua_pushnil(L);
} }
if (lua_pcall(L, 6, 0, -8)) { if (lua_pcall(L, 7, 0, -8)) {
exit(-1); // ERRNO exit(-1); // ERRNO
} }
lua_pop(L, 1); lua_pop(L, 1);

View File

@ -1531,7 +1531,7 @@ local Inotifies = (function()
-- @param filename string filename without path -- @param filename string filename without path
-- @param filename2 -- @param filename2
-- --
local function event(etype, wd, isdir, time, filename, filename2) local function event(etype, wd, isdir, time, filename, wd2, filename2)
local ftype; local ftype;
if isdir then if isdir then
ftype = "directory" ftype = "directory"
@ -1547,35 +1547,53 @@ local Inotifies = (function()
log("Inotify", "got event ", etype, " ", filename) log("Inotify", "got event ", etype, " ", filename)
end end
local ilist = wdlist[wd]
-- looks up the watch descriptor id -- looks up the watch descriptor id
local ilist = wdlist[wd]
if not ilist then if not ilist then
-- this is normal in case of deleted subdirs -- this is normal in case of deleted subdirs
log("Inotify", "event belongs to unknown watch descriptor.") log("Inotify", "event belongs to unknown watch descriptor.")
return return
end end
local ilist2 = wd2 and wdlist[wd2]
-- works through all observers interested in this directory -- works through all observers interested in this directory
for _, inotify in ipairs(ilist) do for _, inotify in ipairs(ilist) do
local path = inotify.path .. filename local path = inotify.path .. filename
local path2 local path2
if filename2 then local etype2 = etype
path2 = inotify.path .. filename2 if filename2 and ilist2 then
local inotify2
-- finds the target directory inotify/watch
for _2, i2 in ipairs(ilist2) do
if inotify.sync == i2.sync then
inotify2 = i2
break
end end
inotify.sync:delay(etype, time, path, path2) end
if not inotify2 then
log("Normal", "Transformed move to Create for ",
inotify.sync.config.name)
etype2 = "Create"
else
path2 = inotify2.path .. filename2
end
end
inotify.sync:delay(etype2, time, path, path2)
-- adds subdirs for new directories -- adds subdirs for new directories
if isdir and inotify.recurse then if isdir and inotify.recurse then
if etype == "Create" then if etype2 == "Create" then
addSync(inotify.root, path, true, inotify.sync, time) addSync(inotify.root, path, true, inotify.sync, time)
elseif etype == "Delete" then elseif etype2 == "Delete" then
removeSync(inotify.sync, path) removeSync(inotify.sync, path)
elseif etype == "Move" then elseif etype2 == "Move" then
removeSync(inotify.sync, path) removeSync(inotify.sync, path)
addSync(inotify.root, path2, true, inotify.sync, time) addSync(inotify.root, path2, true, inotify.sync, time)
end end
end end
end end
-- TODO handle cases where a sync watches target only. XXX
end end
----- -----