2018-03-09 12:05:45 +00:00
|
|
|
require( 'posix' )
|
|
|
|
dofile( 'tests/testlib.lua' )
|
2011-02-25 14:55:15 +00:00
|
|
|
|
2018-03-09 12:05:45 +00:00
|
|
|
cwriteln( '****************************************************************' )
|
|
|
|
cwriteln( ' Testing excludes (rsync)' )
|
|
|
|
cwriteln(' ****************************************************************' )
|
2011-02-25 14:55:15 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
local tdir, srcdir, trgdir = mktemps( )
|
2018-03-09 12:05:45 +00:00
|
|
|
local logfile = tdir .. 'log'
|
|
|
|
local cfgfile = tdir .. 'config.lua'
|
2011-02-25 14:55:15 +00:00
|
|
|
local range = 5
|
2018-03-09 12:05:45 +00:00
|
|
|
local log = { '-log', 'all' }
|
2011-02-25 14:55:15 +00:00
|
|
|
|
|
|
|
writefile(cfgfile, [[
|
2016-12-06 10:11:48 +00:00
|
|
|
settings {
|
2015-10-14 12:23:37 +00:00
|
|
|
logfile = "]]..logfile..[[",
|
|
|
|
nodaemon = true,
|
2011-02-25 14:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sync {
|
2015-10-14 12:23:37 +00:00
|
|
|
default.rsync,
|
2011-02-25 14:55:15 +00:00
|
|
|
source = "]]..srcdir..[[",
|
|
|
|
target = "]]..trgdir..[[",
|
2016-12-06 10:11:48 +00:00
|
|
|
delay = 3,
|
2011-02-25 14:55:15 +00:00
|
|
|
exclude = {
|
2015-10-14 12:23:37 +00:00
|
|
|
"erf",
|
2011-02-25 14:55:15 +00:00
|
|
|
"/eaf",
|
|
|
|
"erd/",
|
|
|
|
"/ead/",
|
|
|
|
},
|
2017-01-05 10:31:29 +00:00
|
|
|
}]])
|
2011-02-25 14:55:15 +00:00
|
|
|
|
|
|
|
-- writes all files
|
2017-01-05 10:31:29 +00:00
|
|
|
local function writefiles
|
|
|
|
( )
|
2018-03-09 12:05:45 +00:00
|
|
|
posix.mkdir( srcdir .. 'd' )
|
|
|
|
writefile( srcdir .. 'erf', 'erf' )
|
|
|
|
writefile( srcdir .. 'eaf', 'erf' )
|
|
|
|
writefile( srcdir .. 'erd', 'erd' )
|
|
|
|
writefile( srcdir .. 'ead', 'ead' )
|
|
|
|
writefile( srcdir .. 'd/erf', 'erf' )
|
|
|
|
writefile( srcdir .. 'd/eaf', 'erf' )
|
|
|
|
writefile( srcdir .. 'd/erd', 'erd' )
|
|
|
|
writefile( srcdir .. 'd/ead', 'ead' )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
--
|
|
|
|
-- Tests if the filename exists
|
|
|
|
-- fails if this is different to expect.
|
|
|
|
--
|
|
|
|
local function testfile
|
|
|
|
(
|
|
|
|
filename,
|
|
|
|
expect
|
|
|
|
)
|
|
|
|
local stat, err = posix.stat( filename )
|
|
|
|
|
|
|
|
if stat and not expect
|
|
|
|
then
|
|
|
|
cwriteln( 'failure: ', filename, ' should be excluded')
|
|
|
|
|
|
|
|
os.exit( 1 )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
2017-01-05 10:31:29 +00:00
|
|
|
|
|
|
|
if not stat and expect
|
|
|
|
then
|
|
|
|
cwriteln( 'failure: ', filename, ' should not be excluded' )
|
|
|
|
os.exit( 1 )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- test all files
|
2017-01-05 10:31:29 +00:00
|
|
|
local function testfiles
|
|
|
|
( )
|
2018-03-09 12:05:45 +00:00
|
|
|
testfile( trgdir .. 'erf', false )
|
|
|
|
testfile( trgdir .. 'eaf', false )
|
|
|
|
testfile( trgdir .. 'erd', true )
|
|
|
|
testfile( trgdir .. 'ead', true )
|
|
|
|
testfile( trgdir .. 'd/erf', false )
|
|
|
|
testfile( trgdir .. 'd/eaf', true )
|
|
|
|
testfile( trgdir .. 'd/erd', true )
|
|
|
|
testfile( trgdir .. 'd/ead', true )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
cwriteln( 'testing startup excludes' )
|
|
|
|
|
|
|
|
writefiles( )
|
|
|
|
|
|
|
|
cwriteln( 'starting Lsyncd' )
|
|
|
|
|
|
|
|
local pid = spawn( './lsyncd', cfgfile, '-log', 'all' )
|
|
|
|
|
|
|
|
cwriteln( 'waiting for Lsyncd to start' )
|
2015-10-14 12:23:37 +00:00
|
|
|
|
|
|
|
posix.sleep( 3 )
|
2017-01-05 10:31:29 +00:00
|
|
|
|
|
|
|
cwriteln( 'testing excludes after startup' )
|
|
|
|
|
|
|
|
testfiles( )
|
|
|
|
|
|
|
|
cwriteln( 'ok, removing sources' )
|
2012-10-07 18:48:09 +00:00
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
if srcdir:sub( 1,4 ) ~= '/tmp'
|
|
|
|
then
|
2011-02-25 14:55:15 +00:00
|
|
|
-- just to make sure before rm -rf
|
2017-01-05 10:31:29 +00:00
|
|
|
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' )
|
|
|
|
|
|
|
|
os.exit( 1 )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
2012-10-07 18:48:09 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
os.execute( 'rm -rf '..srcdir..'/*' )
|
2015-10-14 12:23:37 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
cwriteln( 'waiting for Lsyncd to remove destination' )
|
2015-10-14 12:23:37 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
posix.sleep( 5 )
|
2015-10-14 12:23:37 +00:00
|
|
|
|
|
|
|
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
|
|
|
|
|
|
|
|
if result ~= 'exit' or code ~= 0
|
|
|
|
then
|
2017-01-05 10:31:29 +00:00
|
|
|
cwriteln( 'fail, target directory not empty!' )
|
|
|
|
|
|
|
|
os.exit( 1 )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
cwriteln( 'writing files after startup' )
|
|
|
|
|
|
|
|
writefiles( )
|
|
|
|
|
|
|
|
cwriteln( 'waiting for Lsyncd to transmit changes' )
|
|
|
|
|
|
|
|
posix.sleep( 5 )
|
2012-10-07 18:48:09 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
testfiles( )
|
2011-02-25 14:55:15 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
cwriteln( 'killing started Lsyncd' )
|
|
|
|
|
|
|
|
posix.kill( pid )
|
|
|
|
local _, exitmsg, exitcode = posix.wait( lpid )
|
|
|
|
|
|
|
|
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode );
|
|
|
|
|
|
|
|
if exitcode == 143
|
2015-10-14 12:23:37 +00:00
|
|
|
then
|
2018-03-09 12:05:45 +00:00
|
|
|
cwriteln( 'OK' )
|
2017-01-05 10:31:29 +00:00
|
|
|
os.exit( 0 )
|
2012-10-07 18:48:09 +00:00
|
|
|
else
|
2017-01-05 10:31:29 +00:00
|
|
|
os.exit( 1 )
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO remove temp
|