mirror of https://github.com/octoleo/lsyncd.git
apply filters before inotify watching dirs, actually filter events
This commit is contained in:
parent
465e173983
commit
a78f239fa2
113
lsyncd.lua
113
lsyncd.lua
|
@ -13,10 +13,6 @@
|
||||||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
-- require('profiler')
|
|
||||||
-- profiler.start()
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- A security measurement.
|
-- A security measurement.
|
||||||
-- The core will exit if version ids mismatch.
|
-- The core will exit if version ids mismatch.
|
||||||
|
@ -2181,7 +2177,7 @@ local Filters = ( function
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Tests if 'path' is excluded.
|
-- Tests if 'path' is filtered.
|
||||||
--
|
--
|
||||||
local function test
|
local function test
|
||||||
(
|
(
|
||||||
|
@ -2190,7 +2186,7 @@ local Filters = ( function
|
||||||
)
|
)
|
||||||
if path:byte( 1 ) ~= 47
|
if path:byte( 1 ) ~= 47
|
||||||
then
|
then
|
||||||
error( 'Paths for exlusion tests must start with \'/\'' )
|
error( 'Paths for filter tests must start with \'/\'' )
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, entry in ipairs( self.list )
|
for _, entry in ipairs( self.list )
|
||||||
|
@ -2215,7 +2211,10 @@ local Filters = ( function
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
-- nil means neither a positivie
|
||||||
|
-- or negative hit, thus excludes have to
|
||||||
|
-- be queried
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -2311,14 +2310,35 @@ local Sync = ( function
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Returns true if the relative path is excluded or filtered
|
||||||
|
--
|
||||||
|
local function testFilter
|
||||||
|
(
|
||||||
|
self, -- the Sync
|
||||||
|
path -- the relative path
|
||||||
|
)
|
||||||
|
-- never filter the relative root itself
|
||||||
|
-- ( that would make zero sense )
|
||||||
|
if path == '/' then return false end
|
||||||
|
|
||||||
|
local filter = self.filters and self.filters:test( path )
|
||||||
|
|
||||||
|
if filter ~= nil then return filter end
|
||||||
|
|
||||||
|
-- otherwise check excludes if concerned
|
||||||
|
return self.excludes:test( path )
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Returns true if this Sync concerns about 'path'.
|
-- Returns true if this Sync concerns about 'path'.
|
||||||
--
|
--
|
||||||
local function concerns
|
local function concerns
|
||||||
(
|
(
|
||||||
self,
|
self, -- the Sync
|
||||||
path
|
path -- the absolute path
|
||||||
)
|
)
|
||||||
-- not concerned if watch rootdir doesn't match
|
-- not concerned if watch rootdir doesn't match
|
||||||
if not path:starts( self.source )
|
if not path:starts( self.source )
|
||||||
|
@ -2333,8 +2353,7 @@ local Sync = ( function
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- concerned if not excluded
|
return not testFilter( self, path:sub( #self.source ) )
|
||||||
return not self.excludes:test( path:sub( #self.source ) )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -2348,11 +2367,8 @@ local Sync = ( function
|
||||||
)
|
)
|
||||||
local delay = self.processes[ pid ]
|
local delay = self.processes[ pid ]
|
||||||
|
|
||||||
if not delay
|
-- not a child of this sync?
|
||||||
then
|
if not delay then return end
|
||||||
-- not a child of this sync.
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if delay.status
|
if delay.status
|
||||||
then
|
then
|
||||||
|
@ -2414,11 +2430,8 @@ local Sync = ( function
|
||||||
-- sets the delay on wait again
|
-- sets the delay on wait again
|
||||||
local alarm = self.config.delay
|
local alarm = self.config.delay
|
||||||
|
|
||||||
-- delays at least 1 second
|
-- delays are at least 1 second
|
||||||
if alarm < 1
|
if alarm < 1 then alarm = 1 end
|
||||||
then
|
|
||||||
alarm = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
alarm = now() + alarm
|
alarm = now() + alarm
|
||||||
|
|
||||||
|
@ -2506,29 +2519,33 @@ local Sync = ( function
|
||||||
if not path2
|
if not path2
|
||||||
then
|
then
|
||||||
-- simple test for single path events
|
-- simple test for single path events
|
||||||
if self.excludes:test( path )
|
if testFilter( self, path )
|
||||||
then
|
then
|
||||||
log( 'Exclude', 'excluded ', etype, ' on "', path, '"' )
|
log( 'Filter', 'filtered ', etype, ' on "', path, '"' )
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- for double paths ( move ) it might result into a split
|
-- for double paths ( move ) it might result into a split
|
||||||
local ex1 = self.excludes:test( path )
|
local ex1 = testFilter( self, path )
|
||||||
|
|
||||||
local ex2 = self.excludes:test( path2 )
|
local ex2 = testFilter( self, path2 )
|
||||||
|
|
||||||
if ex1 and ex2
|
if ex1 and ex2
|
||||||
then
|
then
|
||||||
log( 'Exclude', 'excluded "', etype, ' on "', path, '" -> "', path2, '"' )
|
log(
|
||||||
|
'Filter',
|
||||||
|
'filtered "', etype, ' on "', path,
|
||||||
|
'" -> "', path2, '"'
|
||||||
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
elseif not ex1 and ex2
|
elseif not ex1 and ex2
|
||||||
then
|
then
|
||||||
-- splits the move if only partly excluded
|
-- splits the move if only partly excluded
|
||||||
log(
|
log(
|
||||||
'Exclude',
|
'Filter',
|
||||||
'excluded destination transformed ',
|
'filtered destination transformed ',
|
||||||
etype,
|
etype,
|
||||||
' to Delete ',
|
' to Delete ',
|
||||||
path
|
path
|
||||||
|
@ -2541,8 +2558,8 @@ local Sync = ( function
|
||||||
then
|
then
|
||||||
-- splits the move if only partly excluded
|
-- splits the move if only partly excluded
|
||||||
log(
|
log(
|
||||||
'Exclude',
|
'Filter',
|
||||||
'excluded origin transformed ',
|
'filtered origin transformed ',
|
||||||
etype,
|
etype,
|
||||||
' to Create.',
|
' to Create.',
|
||||||
path2
|
path2
|
||||||
|
@ -2554,7 +2571,8 @@ local Sync = ( function
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if etype == 'Move' and not self.config.onMove
|
if etype == 'Move'
|
||||||
|
and not self.config.onMove
|
||||||
then
|
then
|
||||||
-- if there is no move action defined,
|
-- if there is no move action defined,
|
||||||
-- split a move as delete/create
|
-- split a move as delete/create
|
||||||
|
@ -2926,14 +2944,30 @@ local Sync = ( function
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
f:write( 'Excluding:\n' )
|
f:write( 'Filtering:\n' )
|
||||||
|
|
||||||
local nothing = true
|
local nothing = true
|
||||||
|
|
||||||
for t, p in pairs( self.excludes.list )
|
if self.filters
|
||||||
do
|
then
|
||||||
nothing = false
|
for _, e in pairs( self.filters.list )
|
||||||
f:write( t,'\n' )
|
do
|
||||||
|
nothing = false
|
||||||
|
|
||||||
|
f:write( e.rule, ' ', e.pattern,'\n' )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #self.excludes.list > 0
|
||||||
|
then
|
||||||
|
f:write( 'From excludes:\n' )
|
||||||
|
|
||||||
|
for t, p in pairs( self.excludes.list )
|
||||||
|
do
|
||||||
|
nothing = false
|
||||||
|
|
||||||
|
f:write( '- ', t,'\n' )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nothing
|
if nothing
|
||||||
|
@ -2947,12 +2981,13 @@ local Sync = ( function
|
||||||
--
|
--
|
||||||
-- Creates a new Sync.
|
-- Creates a new Sync.
|
||||||
--
|
--
|
||||||
local function new( config )
|
local function new
|
||||||
|
(
|
||||||
|
config
|
||||||
|
)
|
||||||
local s =
|
local s =
|
||||||
{
|
{
|
||||||
-- fields
|
-- fields
|
||||||
|
|
||||||
config = config,
|
config = config,
|
||||||
delays = Queue.new( ),
|
delays = Queue.new( ),
|
||||||
source = config.source,
|
source = config.source,
|
||||||
|
|
Loading…
Reference in New Issue