mirror of https://github.com/octoleo/lsyncd.git
code cleanups
This commit is contained in:
parent
de2d47f7e6
commit
dc93af01aa
113
lsyncd.lua
113
lsyncd.lua
|
@ -2649,15 +2649,18 @@ local Inotify = ( function( )
|
||||||
wd2, -- watch descriptor for target if it's a Move
|
wd2, -- watch descriptor for target if it's a Move
|
||||||
filename2 -- string filename without path of Move target
|
filename2 -- string filename without path of Move target
|
||||||
)
|
)
|
||||||
if isdir then
|
if isdir
|
||||||
|
then
|
||||||
filename = filename .. '/'
|
filename = filename .. '/'
|
||||||
|
|
||||||
if filename2 then
|
if filename2
|
||||||
|
then
|
||||||
filename2 = filename2 .. '/'
|
filename2 = filename2 .. '/'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if filename2 then
|
if filename2
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Inotify',
|
'Inotify',
|
||||||
'got event ',
|
'got event ',
|
||||||
|
@ -2681,47 +2684,58 @@ local Inotify = ( function( )
|
||||||
|
|
||||||
-- looks up the watch descriptor id
|
-- looks up the watch descriptor id
|
||||||
local path = wdpaths[ wd ]
|
local path = wdpaths[ wd ]
|
||||||
if path then
|
|
||||||
|
if path
|
||||||
|
then
|
||||||
path = path..filename
|
path = path..filename
|
||||||
end
|
end
|
||||||
|
|
||||||
local path2 = wd2 and wdpaths[ wd2 ]
|
local path2 = wd2 and wdpaths[ wd2 ]
|
||||||
|
|
||||||
if path2 and filename2 then
|
if path2 and filename2
|
||||||
|
then
|
||||||
path2 = path2..filename2
|
path2 = path2..filename2
|
||||||
end
|
end
|
||||||
|
|
||||||
if not path and path2 and etype == 'Move' then
|
if not path and path2 and etype == 'Move'
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Inotify',
|
'Inotify',
|
||||||
'Move from deleted directory ',
|
'Move from deleted directory ',
|
||||||
path2,
|
path2,
|
||||||
' becomes Create.'
|
' becomes Create.'
|
||||||
)
|
)
|
||||||
|
|
||||||
path = path2
|
path = path2
|
||||||
|
|
||||||
path2 = nil
|
path2 = nil
|
||||||
|
|
||||||
etype = 'Create'
|
etype = 'Create'
|
||||||
end
|
end
|
||||||
|
|
||||||
if not path then
|
if not path
|
||||||
|
then
|
||||||
-- this is normal in case of deleted subdirs
|
-- this is normal in case of deleted subdirs
|
||||||
log(
|
log(
|
||||||
'Inotify',
|
'Inotify',
|
||||||
'event belongs to unknown watch descriptor.'
|
'event belongs to unknown watch descriptor.'
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for sync, root in pairs( syncRoots ) do repeat
|
for sync, root in pairs( syncRoots )
|
||||||
|
do repeat
|
||||||
local relative = splitPath( path, root )
|
local relative = splitPath( path, root )
|
||||||
|
|
||||||
local relative2 = nil
|
local relative2 = nil
|
||||||
|
|
||||||
if path2 then
|
if path2 then
|
||||||
relative2 = splitPath( path2, root )
|
relative2 = splitPath( path2, root )
|
||||||
end
|
end
|
||||||
|
|
||||||
if not relative and not relative2 then
|
if not relative and not relative2
|
||||||
|
then
|
||||||
-- sync is not interested in this dir
|
-- sync is not interested in this dir
|
||||||
break -- continue
|
break -- continue
|
||||||
end
|
end
|
||||||
|
@ -2729,32 +2743,43 @@ local Inotify = ( function( )
|
||||||
-- makes a copy of etype to possibly change it
|
-- makes a copy of etype to possibly change it
|
||||||
local etyped = etype
|
local etyped = etype
|
||||||
|
|
||||||
if etyped == 'Move' then
|
if etyped == 'Move'
|
||||||
if not relative2 then
|
then
|
||||||
|
if not relative2
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Normal',
|
'Normal',
|
||||||
'Transformed Move to Delete for ',
|
'Transformed Move to Delete for ',
|
||||||
sync.config.name
|
sync.config.name
|
||||||
)
|
)
|
||||||
|
|
||||||
etyped = 'Delete'
|
etyped = 'Delete'
|
||||||
elseif not relative then
|
elseif not relative
|
||||||
|
then
|
||||||
relative = relative2
|
relative = relative2
|
||||||
|
|
||||||
relative2 = nil
|
relative2 = nil
|
||||||
|
|
||||||
log(
|
log(
|
||||||
'Normal',
|
'Normal',
|
||||||
'Transformed Move to Create for ',
|
'Transformed Move to Create for ',
|
||||||
sync.config.name
|
sync.config.name
|
||||||
)
|
)
|
||||||
|
|
||||||
etyped = 'Create'
|
etyped = 'Create'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if isdir then
|
if isdir
|
||||||
if etyped == 'Create' then
|
then
|
||||||
|
if etyped == 'Create'
|
||||||
|
then
|
||||||
addWatch( path )
|
addWatch( path )
|
||||||
elseif etyped == 'Delete' then
|
elseif etyped == 'Delete'
|
||||||
|
then
|
||||||
removeWatch( path, true )
|
removeWatch( path, true )
|
||||||
elseif etyped == 'Move' then
|
elseif etyped == 'Move'
|
||||||
|
then
|
||||||
removeWatch( path, false )
|
removeWatch( path, false )
|
||||||
addWatch( path2 )
|
addWatch( path2 )
|
||||||
end
|
end
|
||||||
|
@ -2772,7 +2797,8 @@ local Inotify = ( function( )
|
||||||
|
|
||||||
f:write( 'Inotify watching ', wdpaths:size(), ' directories\n' )
|
f:write( 'Inotify watching ', wdpaths:size(), ' directories\n' )
|
||||||
|
|
||||||
for wd, path in wdpaths:walk( ) do
|
for wd, path in wdpaths:walk( )
|
||||||
|
do
|
||||||
f:write( ' ', wd, ': ', path, '\n' )
|
f:write( ' ', wd, ': ', path, '\n' )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2815,7 +2841,8 @@ local Fsevents = ( function( )
|
||||||
--
|
--
|
||||||
local function addSync( sync, dir )
|
local function addSync( sync, dir )
|
||||||
|
|
||||||
if syncRoots[ sync ] then
|
if syncRoots[ sync ]
|
||||||
|
then
|
||||||
error( 'duplicate sync in Fanotify.addSync()' )
|
error( 'duplicate sync in Fanotify.addSync()' )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2833,10 +2860,12 @@ local Fsevents = ( function( )
|
||||||
path, -- path of file
|
path, -- path of file
|
||||||
path2 -- path of target in case of 'Move'
|
path2 -- path of target in case of 'Move'
|
||||||
)
|
)
|
||||||
if isdir then
|
if isdir
|
||||||
|
then
|
||||||
path = path .. '/'
|
path = path .. '/'
|
||||||
|
|
||||||
if path2 then
|
if path2
|
||||||
|
then
|
||||||
path2 = path2 .. '/'
|
path2 = path2 .. '/'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2850,34 +2879,56 @@ local Fsevents = ( function( )
|
||||||
path2
|
path2
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, sync in Syncs.iwalk() do repeat
|
for _, sync in Syncs.iwalk()
|
||||||
|
do repeat
|
||||||
|
|
||||||
local root = sync.source
|
local root = sync.source
|
||||||
|
|
||||||
-- TODO combine ifs
|
-- TODO combine ifs
|
||||||
if not path:starts( root ) then
|
if not path:starts( root )
|
||||||
if not path2 or not path2:starts( root ) then
|
then
|
||||||
|
if not path2 or not path2:starts( root )
|
||||||
|
then
|
||||||
break -- continue
|
break -- continue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local relative = splitPath( path, root )
|
local relative = splitPath( path, root )
|
||||||
|
|
||||||
local relative2
|
local relative2
|
||||||
if path2 then
|
|
||||||
|
if path2
|
||||||
|
then
|
||||||
relative2 = splitPath( path2, root )
|
relative2 = splitPath( path2, root )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- possibly change etype for this iteration only
|
-- possibly change etype for this iteration only
|
||||||
local etyped = etype
|
local etyped = etype
|
||||||
if etyped == 'Move' then
|
|
||||||
if not relative2 then
|
if etyped == 'Move'
|
||||||
log('Normal', 'Transformed Move to Delete for ', sync.config.name)
|
then
|
||||||
|
if not relative2
|
||||||
|
then
|
||||||
|
log(
|
||||||
|
'Normal',
|
||||||
|
'Transformed Move to Delete for ',
|
||||||
|
sync.config.name
|
||||||
|
)
|
||||||
|
|
||||||
etyped = 'Delete'
|
etyped = 'Delete'
|
||||||
elseif not relative then
|
|
||||||
|
elseif not relative
|
||||||
|
then
|
||||||
relative = relative2
|
relative = relative2
|
||||||
|
|
||||||
relative2 = nil
|
relative2 = nil
|
||||||
log('Normal', 'Transformed Move to Create for ', sync.config.name)
|
|
||||||
|
log(
|
||||||
|
'Normal',
|
||||||
|
'Transformed Move to Create for ',
|
||||||
|
sync.config.name
|
||||||
|
)
|
||||||
|
|
||||||
etyped = 'Create'
|
etyped = 'Create'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue