mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-07 09:04:05 +00:00
cleanups
This commit is contained in:
parent
b79defadb3
commit
d444ccb2d2
12
lsyncd.c
12
lsyncd.c
@ -1483,9 +1483,10 @@ l_stackdump( lua_State * L )
|
|||||||
| values are boolean true on dirs.
|
| values are boolean true on dirs.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
l_readdir ( lua_State *L )
|
l_readdir( lua_State *L )
|
||||||
{
|
{
|
||||||
const char * dirname = luaL_checkstring( L, 1 );
|
const char * dirname = luaL_checkstring( L, 1 );
|
||||||
|
|
||||||
DIR *d;
|
DIR *d;
|
||||||
|
|
||||||
d = opendir( dirname );
|
d = opendir( dirname );
|
||||||
@ -1507,16 +1508,15 @@ l_readdir ( lua_State *L )
|
|||||||
struct dirent *de = readdir( d );
|
struct dirent *de = readdir( d );
|
||||||
bool isdir;
|
bool isdir;
|
||||||
|
|
||||||
if( de == NULL )
|
if( de == NULL ) // finished
|
||||||
{
|
{
|
||||||
// finished
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignores . and ..
|
// ignores . and ..
|
||||||
if(
|
if(
|
||||||
!strcmp( de->d_name, "." ) ||
|
!strcmp( de->d_name, "." )
|
||||||
!strcmp( de->d_name, ".." )
|
|| !strcmp( de->d_name, ".." )
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -1572,7 +1572,7 @@ l_readdir ( lua_State *L )
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
l_terminate(lua_State *L)
|
l_terminate( lua_State *L )
|
||||||
{
|
{
|
||||||
int exitcode = luaL_checkinteger( L, 1 );
|
int exitcode = luaL_checkinteger( L, 1 );
|
||||||
|
|
||||||
|
69
lsyncd.lua
69
lsyncd.lua
@ -803,7 +803,8 @@ local InletFactory = ( function( )
|
|||||||
-- Removes the trailing slash from a path.
|
-- Removes the trailing slash from a path.
|
||||||
--
|
--
|
||||||
local function cutSlash( path )
|
local function cutSlash( path )
|
||||||
if string.byte(path, -1) == 47 then
|
if string.byte(path, -1) == 47
|
||||||
|
then
|
||||||
return string.sub(path, 1, -2)
|
return string.sub(path, 1, -2)
|
||||||
else
|
else
|
||||||
return path
|
return path
|
||||||
@ -814,7 +815,8 @@ local InletFactory = ( function( )
|
|||||||
-- Gets the path of an event.
|
-- Gets the path of an event.
|
||||||
--
|
--
|
||||||
local function getPath( event )
|
local function getPath( event )
|
||||||
if event.move ~= 'To' then
|
if event.move ~= 'To'
|
||||||
|
then
|
||||||
return e2d[ event ].path
|
return e2d[ event ].path
|
||||||
else
|
else
|
||||||
return e2d[ event ].path2
|
return e2d[ event ].path2
|
||||||
@ -1017,9 +1019,10 @@ local InletFactory = ( function( )
|
|||||||
--
|
--
|
||||||
getPaths = function( elist, mutator )
|
getPaths = function( elist, mutator )
|
||||||
|
|
||||||
local dlist = e2d[elist]
|
local dlist = e2d[ elist ]
|
||||||
|
|
||||||
if not dlist then
|
if not dlist
|
||||||
|
then
|
||||||
error( 'cannot find delay list from event list.' )
|
error( 'cannot find delay list from event list.' )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1057,17 +1060,20 @@ local InletFactory = ( function( )
|
|||||||
|
|
||||||
__index = function( elist, func )
|
__index = function( elist, func )
|
||||||
|
|
||||||
if func == 'isList' then
|
if func == 'isList'
|
||||||
|
then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if func == 'config' then
|
if func == 'config'
|
||||||
|
then
|
||||||
return e2d[ elist ].sync.config
|
return e2d[ elist ].sync.config
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = eventListFuncs[ func ]
|
local f = eventListFuncs[ func ]
|
||||||
|
|
||||||
if not f then
|
if not f
|
||||||
|
then
|
||||||
error(
|
error(
|
||||||
'event list does not have function "' .. func .. '"',
|
'event list does not have function "' .. func .. '"',
|
||||||
2
|
2
|
||||||
@ -1100,9 +1106,10 @@ local InletFactory = ( function( )
|
|||||||
-- already created?
|
-- already created?
|
||||||
local eu = e2d2[delay]
|
local eu = e2d2[delay]
|
||||||
|
|
||||||
if delay.etype ~= 'Move' then
|
if delay.etype ~= 'Move'
|
||||||
|
then
|
||||||
if eu then
|
if eu
|
||||||
|
then
|
||||||
return eu
|
return eu
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1115,7 +1122,8 @@ local InletFactory = ( function( )
|
|||||||
|
|
||||||
else
|
else
|
||||||
-- moves have 2 events - origin and destination
|
-- moves have 2 events - origin and destination
|
||||||
if eu then
|
if eu
|
||||||
|
then
|
||||||
return eu[1], eu[2]
|
return eu[1], eu[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1132,7 +1140,6 @@ local InletFactory = ( function( )
|
|||||||
|
|
||||||
-- move events have a field 'move'
|
-- move events have a field 'move'
|
||||||
return event, event2
|
return event, event2
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1143,7 +1150,8 @@ local InletFactory = ( function( )
|
|||||||
|
|
||||||
local eu = e2d2[ dlist ]
|
local eu = e2d2[ dlist ]
|
||||||
|
|
||||||
if eu then
|
if eu
|
||||||
|
then
|
||||||
return eu
|
return eu
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1152,10 +1160,10 @@ local InletFactory = ( function( )
|
|||||||
setmetatable( elist, eventListMeta )
|
setmetatable( elist, eventListMeta )
|
||||||
|
|
||||||
e2d [ elist ] = dlist
|
e2d [ elist ] = dlist
|
||||||
|
|
||||||
e2d2[ dlist ] = elist
|
e2d2[ dlist ] = elist
|
||||||
|
|
||||||
return elist
|
return elist
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -1186,7 +1194,8 @@ local InletFactory = ( function( )
|
|||||||
local e = { }
|
local e = { }
|
||||||
local en = 1;
|
local en = 1;
|
||||||
|
|
||||||
for k, _ in pairs( sync.excludes.list ) do
|
for k, _ in pairs( sync.excludes.list )
|
||||||
|
do
|
||||||
e[ en ] = k;
|
e[ en ] = k;
|
||||||
en = en + 1;
|
en = en + 1;
|
||||||
end
|
end
|
||||||
@ -1207,14 +1216,18 @@ local InletFactory = ( function( )
|
|||||||
--
|
--
|
||||||
discardEvent = function( sync, event )
|
discardEvent = function( sync, event )
|
||||||
local delay = e2d[ event ]
|
local delay = e2d[ event ]
|
||||||
if delay.status ~= 'wait' then
|
|
||||||
|
if delay.status ~= 'wait'
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Error',
|
'Error',
|
||||||
'Ignored cancel of a non-waiting event of type ',
|
'Ignored cancel of a non-waiting event of type ',
|
||||||
event.etype
|
event.etype
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
sync:removeDelay( delay )
|
sync:removeDelay( delay )
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -1232,6 +1245,7 @@ local InletFactory = ( function( )
|
|||||||
--
|
--
|
||||||
getEvents = function( sync, test )
|
getEvents = function( sync, test )
|
||||||
local dlist = sync:getDelays( test )
|
local dlist = sync:getDelays( test )
|
||||||
|
|
||||||
return dl2el( dlist )
|
return dl2el( dlist )
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -2599,7 +2613,7 @@ local Inotify = ( function( )
|
|||||||
-- @param path absolute path of directory to observe
|
-- @param path absolute path of directory to observe
|
||||||
-- @param recurse true if recursing into subdirs
|
-- @param recurse true if recursing into subdirs
|
||||||
--
|
--
|
||||||
local function addWatch(path)
|
local function addWatch( path )
|
||||||
|
|
||||||
log(
|
log(
|
||||||
'Function',
|
'Function',
|
||||||
@ -2608,8 +2622,10 @@ local Inotify = ( function( )
|
|||||||
' )'
|
' )'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not Syncs.concerns(path) then
|
if not Syncs.concerns(path)
|
||||||
|
then
|
||||||
log('Inotify', 'not concerning "',path,'"')
|
log('Inotify', 'not concerning "',path,'"')
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2618,7 +2634,8 @@ local Inotify = ( function( )
|
|||||||
|
|
||||||
local wd = lsyncd.inotify.addwatch( path, inotifyMode) ;
|
local wd = lsyncd.inotify.addwatch( path, inotifyMode) ;
|
||||||
|
|
||||||
if wd < 0 then
|
if wd < 0
|
||||||
|
then
|
||||||
log( 'Inotify','Unable to add watch "', path, '"' )
|
log( 'Inotify','Unable to add watch "', path, '"' )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -2627,23 +2644,29 @@ local Inotify = ( function( )
|
|||||||
-- If this watch descriptor is registered already
|
-- If this watch descriptor is registered already
|
||||||
-- the kernel reuses it since old dir is gone.
|
-- the kernel reuses it since old dir is gone.
|
||||||
local op = wdpaths[ wd ]
|
local op = wdpaths[ wd ]
|
||||||
if op and op ~= path then
|
|
||||||
|
if op and op ~= path
|
||||||
|
then
|
||||||
pathwds[ op ] = nil
|
pathwds[ op ] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pathwds[ path ] = wd
|
pathwds[ path ] = wd
|
||||||
|
|
||||||
wdpaths[ wd ] = path
|
wdpaths[ wd ] = path
|
||||||
|
|
||||||
-- registers and adds watches for all subdirectories
|
-- registers and adds watches for all subdirectories
|
||||||
local entries = lsyncd.readdir( path )
|
local entries = lsyncd.readdir( path )
|
||||||
|
|
||||||
if not entries then
|
if not entries
|
||||||
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for dirname, isdir in pairs( entries ) do
|
for dirname, isdir in pairs( entries )
|
||||||
if isdir then
|
do
|
||||||
|
if isdir
|
||||||
|
then
|
||||||
addWatch( path .. dirname .. '/' )
|
addWatch( path .. dirname .. '/' )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user