mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-06 00:30:46 +00:00
check for excludes if adding inotify watches
This commit is contained in:
parent
f6182cb9f6
commit
a9eab69298
60
lsyncd.lua
60
lsyncd.lua
@ -946,11 +946,11 @@ local Excludes = (function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Tests if 'file' is excluded.
|
-- Tests if 'path' is excluded.
|
||||||
--
|
--
|
||||||
local function test(self, file)
|
local function test(self, path)
|
||||||
for _, p in pairs(self.list) do
|
for _, p in pairs(self.list) do
|
||||||
if (string.match(file, p)) then
|
if (string.match(path, p)) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1027,6 +1027,28 @@ local Sync = (function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Returns true if this Sync concerns about
|
||||||
|
-- 'path'
|
||||||
|
--
|
||||||
|
local function concerns(self, path)
|
||||||
|
-- not concerned if watch rootdir doesnt match
|
||||||
|
if not self.source:starts(path) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
print("subdirtest", path:sub(#self.source, -1))
|
||||||
|
|
||||||
|
-- a sub dir and not concerned about subdirs
|
||||||
|
if self.config.subdirs ~= nil and not self.config.subdirs and
|
||||||
|
path:sub(#self.source, -1):match("[^/]+/?")
|
||||||
|
then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- concerned if not excluded
|
||||||
|
return not self.excludes:test(path)
|
||||||
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Collects a child process
|
-- Collects a child process
|
||||||
--
|
--
|
||||||
@ -1376,6 +1398,9 @@ local Sync = (function()
|
|||||||
f:write("\n")
|
f:write("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- b
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Creates a new Sync
|
-- Creates a new Sync
|
||||||
--
|
--
|
||||||
@ -1392,6 +1417,7 @@ local Sync = (function()
|
|||||||
addBlanketDelay = addBlanketDelay,
|
addBlanketDelay = addBlanketDelay,
|
||||||
addExclude = addExclude,
|
addExclude = addExclude,
|
||||||
collect = collect,
|
collect = collect,
|
||||||
|
concerns = concerns,
|
||||||
delay = delay,
|
delay = delay,
|
||||||
getAlarm = getAlarm,
|
getAlarm = getAlarm,
|
||||||
getDelays = getDelays,
|
getDelays = getDelays,
|
||||||
@ -1571,8 +1597,23 @@ local Syncs = (function()
|
|||||||
return #list
|
return #list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
------
|
||||||
|
-- tests if any sync is interested in path
|
||||||
|
--
|
||||||
|
local function concerns(path)
|
||||||
|
for _, s in ipairs(list) do
|
||||||
|
if s:concerns(path) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
-- public interface
|
-- public interface
|
||||||
return {add = add, iwalk = iwalk, size = size}
|
return {add = add,
|
||||||
|
concerns = concerns,
|
||||||
|
iwalk = iwalk,
|
||||||
|
size = size}
|
||||||
end)()
|
end)()
|
||||||
|
|
||||||
|
|
||||||
@ -1650,6 +1691,11 @@ local Inotify = (function()
|
|||||||
"Inotify.addWatch(",path,", ",recurse,", ",
|
"Inotify.addWatch(",path,", ",recurse,", ",
|
||||||
raiseSync,", ",raiseTime,")")
|
raiseSync,", ",raiseTime,")")
|
||||||
|
|
||||||
|
if not Syncs.concerns(path) then
|
||||||
|
log("Inotify", "not concerning '",path,"'")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- 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
|
||||||
@ -1693,7 +1739,7 @@ local Inotify = (function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- adds syncs for subdirs
|
-- adds syncs for subdirs
|
||||||
if isdir and recurse then
|
if isdir then
|
||||||
addWatch(pd, true, raiseSync, raiseTime)
|
addWatch(pd, true, raiseSync, raiseTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1794,9 +1840,7 @@ local Inotify = (function()
|
|||||||
end
|
end
|
||||||
sync:delay(etyped, time, relative, relative2)
|
sync:delay(etyped, time, relative, relative2)
|
||||||
|
|
||||||
if isdir and
|
if isdir then
|
||||||
(sync.config.subdirs or sync.config.subdirs == nil)
|
|
||||||
then
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user