mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-22 14:48:29 +00:00
fixed watch descriptor mixups
This commit is contained in:
parent
83aed80aa7
commit
26b4b65976
49
lsyncd.lua
49
lsyncd.lua
@ -1487,6 +1487,25 @@ local Inotifies = (function()
|
|||||||
--
|
--
|
||||||
local syncRoots = {}
|
local syncRoots = {}
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Stops watching a directory
|
||||||
|
--
|
||||||
|
-- @param path absolute path to unwatch
|
||||||
|
-- @param core if false not actually send the unwatch to the kernel
|
||||||
|
-- (used in moves which reuse the watch)
|
||||||
|
--
|
||||||
|
local function removeWatch(path, core)
|
||||||
|
local wd = pathwds[path]
|
||||||
|
if not wd then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if core then
|
||||||
|
lsyncd.inotify.rmwatch(wd)
|
||||||
|
end
|
||||||
|
wdpaths[wd] = nil
|
||||||
|
pathwds[path] = nil
|
||||||
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Adds watches for a directory (optionally) including all subdirectories.
|
-- Adds watches for a directory (optionally) including all subdirectories.
|
||||||
--
|
--
|
||||||
@ -1501,17 +1520,24 @@ local Inotifies = (function()
|
|||||||
"Inotifies.addWatch(",path,", ",recurse,", ",
|
"Inotifies.addWatch(",path,", ",recurse,", ",
|
||||||
raiseSync,", ",raiseTime,")")
|
raiseSync,", ",raiseTime,")")
|
||||||
|
|
||||||
local wd = pathwds[path]
|
|
||||||
if not wd then
|
|
||||||
-- lets the core registers watch with the kernel
|
-- lets the core registers watch with the kernel
|
||||||
local wd = lsyncd.inotify.addwatch(path);
|
local wd = lsyncd.inotify.addwatch(path);
|
||||||
if wd < 0 then
|
if wd < 0 then
|
||||||
log("Error","Failure adding watch ",path," -> ignored ")
|
log("Error","Failure adding watch ",path," -> ignored ")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- If this wd is registered already the kernel
|
||||||
|
-- reused it for a new dir for a reason - old
|
||||||
|
-- dir is gone.
|
||||||
|
local op = wdpaths[wd]
|
||||||
|
if op and op ~= path then
|
||||||
|
pathwds[op] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
pathwds[path] = wd
|
pathwds[path] = wd
|
||||||
wdpaths[wd] = path
|
wdpaths[wd] = path
|
||||||
end
|
|
||||||
|
|
||||||
-- registers and adds watches for all subdirectories
|
-- registers and adds watches for all subdirectories
|
||||||
-- and/or raises create events for all entries
|
-- and/or raises create events for all entries
|
||||||
@ -1543,19 +1569,6 @@ local Inotifies = (function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
|
||||||
-- Stops watching a directory
|
|
||||||
--
|
|
||||||
local function removeWatch(path)
|
|
||||||
local wd = pathwds[path]
|
|
||||||
if not wd then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
lsyncd.inotify.rmwatch(wd)
|
|
||||||
wdpaths[wd] = nil
|
|
||||||
pathwds[path] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- adds a Sync to receive events
|
-- adds a Sync to receive events
|
||||||
--
|
--
|
||||||
@ -1657,9 +1670,9 @@ local Inotifies = (function()
|
|||||||
if etyped == "Create" then
|
if etyped == "Create" then
|
||||||
addWatch(path, true, sync, time)
|
addWatch(path, true, sync, time)
|
||||||
elseif etyped == "Delete" then
|
elseif etyped == "Delete" then
|
||||||
removeWatch(path)
|
removeWatch(path, true)
|
||||||
elseif etyped == "Move" then
|
elseif etyped == "Move" then
|
||||||
removeWatch(path)
|
removeWatch(path, false)
|
||||||
addWatch(path2, true, sync, time)
|
addWatch(path2, true, sync, time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,8 +16,10 @@ 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","Inotify","-log","Exec")
|
local logs = {}
|
||||||
|
--logs = {"-log", "Inotify", "-log", "Exec" }
|
||||||
|
local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir, unpack(logs))
|
||||||
|
|
||||||
cwriteln("waiting for Lsyncd to startup")
|
cwriteln("waiting for Lsyncd to startup")
|
||||||
posix.sleep(1)
|
posix.sleep(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user