mirror of https://github.com/octoleo/lsyncd.git
new rsync control is no longer recursive, fixing excludes
This commit is contained in:
parent
1b09a56320
commit
0c5e2c707e
|
@ -186,7 +186,6 @@ rsync.action = function
|
||||||
config.rsync.binary,
|
config.rsync.binary,
|
||||||
'<', table.concat( paths, '\000' ),
|
'<', table.concat( paths, '\000' ),
|
||||||
config.rsync._computed,
|
config.rsync._computed,
|
||||||
'-r',
|
|
||||||
delete,
|
delete,
|
||||||
'--force',
|
'--force',
|
||||||
'--from0',
|
'--from0',
|
||||||
|
|
|
@ -157,6 +157,15 @@ rsyncssh.action = function
|
||||||
-- deletes create multi match patterns
|
-- deletes create multi match patterns
|
||||||
local paths = elist.getPaths( )
|
local paths = elist.getPaths( )
|
||||||
|
|
||||||
|
-- removes trailing slashes from dirs.
|
||||||
|
for k, v in ipairs( paths )
|
||||||
|
do
|
||||||
|
if string.byte( v, -1 ) == 47
|
||||||
|
then
|
||||||
|
paths[ k ] = string.sub( v, 1, -2 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
log(
|
log(
|
||||||
'Normal',
|
'Normal',
|
||||||
'Rsyncing list\n',
|
'Rsyncing list\n',
|
||||||
|
@ -176,7 +185,6 @@ rsyncssh.action = function
|
||||||
config.rsync.binary,
|
config.rsync.binary,
|
||||||
'<', table.concat( paths, '\000' ),
|
'<', table.concat( paths, '\000' ),
|
||||||
config.rsync._computed,
|
config.rsync._computed,
|
||||||
'-r',
|
|
||||||
delete,
|
delete,
|
||||||
'--force',
|
'--force',
|
||||||
'--from0',
|
'--from0',
|
||||||
|
|
14
lsyncd.lua
14
lsyncd.lua
|
@ -1852,13 +1852,13 @@ local Excludes = ( function( )
|
||||||
p = string.gsub( p, '%[%^/%]%*%[%^/%]%*', '.*' )
|
p = string.gsub( p, '%[%^/%]%*%[%^/%]%*', '.*' )
|
||||||
p = string.gsub( p, '^/', '^/' )
|
p = string.gsub( p, '^/', '^/' )
|
||||||
|
|
||||||
if p:sub( 1, 2 ) ~= '^/'
|
-- if p:sub( 1, 2 ) ~= '^/'
|
||||||
then
|
-- then
|
||||||
-- if does not begin with '^/'
|
-- -- if does not begin with '^/'
|
||||||
-- then all matches should begin with '/'.
|
-- -- then all matches should begin with '/'.
|
||||||
p = '/' .. p;
|
-- p = '/' .. p;
|
||||||
end
|
-- end
|
||||||
|
--
|
||||||
log(
|
log(
|
||||||
'Exclude',
|
'Exclude',
|
||||||
'toLuaPattern "',
|
'toLuaPattern "',
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
require("posix")
|
require("posix")
|
||||||
dofile("tests/testlib.lua")
|
dofile("tests/testlib.lua")
|
||||||
|
|
||||||
cwriteln("****************************************************************")
|
cwriteln('****************************************************************' )
|
||||||
cwriteln(" Testing excludes ")
|
cwriteln(' Testing excludes' )
|
||||||
cwriteln("****************************************************************")
|
cwriteln('****************************************************************' )
|
||||||
|
|
||||||
local tdir, srcdir, trgdir = mktemps()
|
local tdir, srcdir, trgdir = mktemps( )
|
||||||
local logfile = tdir .. "log"
|
local logfile = tdir .. "log"
|
||||||
local cfgfile = tdir .. "config.lua"
|
local cfgfile = tdir .. "config.lua"
|
||||||
local range = 5
|
local range = 5
|
||||||
|
@ -29,96 +29,126 @@ sync {
|
||||||
"erd/",
|
"erd/",
|
||||||
"/ead/",
|
"/ead/",
|
||||||
},
|
},
|
||||||
}]]);
|
}]])
|
||||||
|
|
||||||
-- writes all files
|
-- writes all files
|
||||||
local function writefiles()
|
local function writefiles
|
||||||
posix.mkdir(srcdir .. "d");
|
( )
|
||||||
writefile(srcdir .. "erf", "erf");
|
posix.mkdir( srcdir .. "d" )
|
||||||
writefile(srcdir .. "eaf", "erf");
|
writefile( srcdir .. "erf", "erf" )
|
||||||
writefile(srcdir .. "erd", "erd");
|
writefile( srcdir .. "eaf", "erf" )
|
||||||
writefile(srcdir .. "ead", "ead");
|
writefile( srcdir .. "erd", "erd" )
|
||||||
writefile(srcdir .. "d/erf", "erf");
|
writefile( srcdir .. "ead", "ead" )
|
||||||
writefile(srcdir .. "d/eaf", "erf");
|
writefile( srcdir .. "d/erf", "erf" )
|
||||||
writefile(srcdir .. "d/erd", "erd");
|
writefile( srcdir .. "d/eaf", "erf" )
|
||||||
writefile(srcdir .. "d/ead", "ead");
|
writefile( srcdir .. "d/erd", "erd" )
|
||||||
|
writefile( srcdir .. "d/ead", "ead" )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- test if the filename exists, fails if this is different to expect
|
--
|
||||||
local function testfile(filename, expect)
|
-- Tests if the filename exists
|
||||||
local stat, err = posix.stat(filename)
|
-- fails if this is different to expect.
|
||||||
if stat and not expect then
|
--
|
||||||
cwriteln("failure: ",filename," should be excluded");
|
local function testfile
|
||||||
os.exit(1);
|
(
|
||||||
|
filename,
|
||||||
|
expect
|
||||||
|
)
|
||||||
|
local stat, err = posix.stat( filename )
|
||||||
|
|
||||||
|
if stat and not expect
|
||||||
|
then
|
||||||
|
cwriteln( 'failure: ', filename, ' should be excluded')
|
||||||
|
|
||||||
|
os.exit( 1 )
|
||||||
end
|
end
|
||||||
if not stat and expect then
|
|
||||||
cwriteln("failure: ",filename," should not be excluded");
|
if not stat and expect
|
||||||
os.exit(1);
|
then
|
||||||
|
cwriteln( 'failure: ', filename, ' should not be excluded' )
|
||||||
|
os.exit( 1 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- test all files
|
-- test all files
|
||||||
local function testfiles()
|
local function testfiles
|
||||||
testfile(trgdir .. "erf", false);
|
( )
|
||||||
testfile(trgdir .. "eaf", false);
|
testfile( trgdir .. "erf", false )
|
||||||
testfile(trgdir .. "erd", true);
|
testfile( trgdir .. "eaf", false )
|
||||||
testfile(trgdir .. "ead", true);
|
testfile( trgdir .. "erd", true )
|
||||||
testfile(trgdir .. "d/erf", false);
|
testfile( trgdir .. "ead", true )
|
||||||
testfile(trgdir .. "d/eaf", true);
|
testfile( trgdir .. "d/erf", false )
|
||||||
testfile(trgdir .. "d/erd", true);
|
testfile( trgdir .. "d/eaf", true )
|
||||||
testfile(trgdir .. "d/ead", true);
|
testfile( trgdir .. "d/erd", true )
|
||||||
|
testfile( trgdir .. "d/ead", true )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
cwriteln( 'testing startup excludes' );
|
cwriteln( 'testing startup excludes' )
|
||||||
writefiles( );
|
|
||||||
cwriteln( 'starting Lsyncd' );
|
writefiles( )
|
||||||
local pid = spawn( './lsyncd', cfgfile, '-log', 'all');
|
|
||||||
|
cwriteln( 'starting Lsyncd' )
|
||||||
|
|
||||||
|
local pid = spawn( './lsyncd', cfgfile, '-log', 'all' )
|
||||||
|
|
||||||
|
cwriteln( 'waiting for Lsyncd to start' )
|
||||||
|
|
||||||
cwriteln( 'waiting for Lsyncd to start' );
|
|
||||||
posix.sleep( 3 )
|
posix.sleep( 3 )
|
||||||
cwriteln( 'testing excludes after startup' );
|
|
||||||
testfiles( );
|
cwriteln( 'testing excludes after startup' )
|
||||||
cwriteln( 'ok, removing sources' );
|
|
||||||
|
testfiles( )
|
||||||
|
|
||||||
|
cwriteln( 'ok, removing sources' )
|
||||||
|
|
||||||
if srcdir:sub( 1,4 ) ~= '/tmp'
|
if srcdir:sub( 1,4 ) ~= '/tmp'
|
||||||
then
|
then
|
||||||
-- just to make sure before rm -rf
|
-- just to make sure before rm -rf
|
||||||
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' );
|
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' )
|
||||||
os.exit( 1 );
|
|
||||||
|
os.exit( 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
os.execute( 'rm -rf '..srcdir..'/*' );
|
os.execute( 'rm -rf '..srcdir..'/*' )
|
||||||
|
|
||||||
cwriteln( 'waiting for Lsyncd to remove destination' );
|
cwriteln( 'waiting for Lsyncd to remove destination' )
|
||||||
|
|
||||||
posix.sleep( 5 );
|
posix.sleep( 5 )
|
||||||
|
|
||||||
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
|
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
|
||||||
|
|
||||||
if result ~= 'exit' or code ~= 0
|
if result ~= 'exit' or code ~= 0
|
||||||
then
|
then
|
||||||
cwriteln( 'fail, target directory not empty!' );
|
cwriteln( 'fail, target directory not empty!' )
|
||||||
os.exit( 1 );
|
|
||||||
|
os.exit( 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
cwriteln( 'writing files after startup' );
|
cwriteln( 'writing files after startup' )
|
||||||
writefiles( );
|
|
||||||
cwriteln( 'waiting for Lsyncd to transmit changes' );
|
|
||||||
posix.sleep( 5 );
|
|
||||||
testfiles( );
|
|
||||||
|
|
||||||
cwriteln( 'killing started Lsyncd' );
|
writefiles( )
|
||||||
posix.kill( pid );
|
|
||||||
local _, exitmsg, lexitcode = posix.wait( lpid );
|
|
||||||
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode );
|
|
||||||
|
|
||||||
if lexitcode == 143
|
cwriteln( 'waiting for Lsyncd to transmit changes' )
|
||||||
|
|
||||||
|
posix.sleep( 5 )
|
||||||
|
|
||||||
|
testfiles( )
|
||||||
|
|
||||||
|
cwriteln( 'killing started Lsyncd' )
|
||||||
|
|
||||||
|
posix.kill( pid )
|
||||||
|
local _, exitmsg, exitcode = posix.wait( lpid )
|
||||||
|
|
||||||
|
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode );
|
||||||
|
|
||||||
|
if exitcode == 143
|
||||||
then
|
then
|
||||||
cwriteln( "OK" );
|
cwriteln( "OK" )
|
||||||
os.exit( 0 );
|
|
||||||
|
os.exit( 0 )
|
||||||
else
|
else
|
||||||
os.exit( 1 );
|
os.exit( 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO remove temp
|
-- TODO remove temp
|
||||||
|
|
Loading…
Reference in New Issue