From 0c5e2c707e499065240343b8db28f21f2e8a8156 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Thu, 5 Jan 2017 11:31:29 +0100 Subject: [PATCH] new rsync control is no longer recursive, fixing excludes --- default-rsync.lua | 1 - default-rsyncssh.lua | 10 ++- lsyncd.lua | 14 ++-- tests/exclude-rsync.lua | 152 ++++++++++++++++++++++++---------------- 4 files changed, 107 insertions(+), 70 deletions(-) diff --git a/default-rsync.lua b/default-rsync.lua index 81fb129..b8392e5 100644 --- a/default-rsync.lua +++ b/default-rsync.lua @@ -186,7 +186,6 @@ rsync.action = function config.rsync.binary, '<', table.concat( paths, '\000' ), config.rsync._computed, - '-r', delete, '--force', '--from0', diff --git a/default-rsyncssh.lua b/default-rsyncssh.lua index 4baad3f..f30200c 100644 --- a/default-rsyncssh.lua +++ b/default-rsyncssh.lua @@ -157,6 +157,15 @@ rsyncssh.action = function -- deletes create multi match patterns 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( 'Normal', 'Rsyncing list\n', @@ -176,7 +185,6 @@ rsyncssh.action = function config.rsync.binary, '<', table.concat( paths, '\000' ), config.rsync._computed, - '-r', delete, '--force', '--from0', diff --git a/lsyncd.lua b/lsyncd.lua index f440e35..adabdf8 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -1852,13 +1852,13 @@ local Excludes = ( function( ) p = string.gsub( p, '%[%^/%]%*%[%^/%]%*', '.*' ) p = string.gsub( p, '^/', '^/' ) - if p:sub( 1, 2 ) ~= '^/' - then - -- if does not begin with '^/' - -- then all matches should begin with '/'. - p = '/' .. p; - end - +-- if p:sub( 1, 2 ) ~= '^/' +-- then +-- -- if does not begin with '^/' +-- -- then all matches should begin with '/'. +-- p = '/' .. p; +-- end +-- log( 'Exclude', 'toLuaPattern "', diff --git a/tests/exclude-rsync.lua b/tests/exclude-rsync.lua index 5ff5475..0fac8cc 100755 --- a/tests/exclude-rsync.lua +++ b/tests/exclude-rsync.lua @@ -2,11 +2,11 @@ require("posix") dofile("tests/testlib.lua") -cwriteln("****************************************************************") -cwriteln(" Testing excludes ") -cwriteln("****************************************************************") +cwriteln('****************************************************************' ) +cwriteln(' Testing excludes' ) +cwriteln('****************************************************************' ) -local tdir, srcdir, trgdir = mktemps() +local tdir, srcdir, trgdir = mktemps( ) local logfile = tdir .. "log" local cfgfile = tdir .. "config.lua" local range = 5 @@ -29,96 +29,126 @@ sync { "erd/", "/ead/", }, -}]]); +}]]) -- writes all files -local function writefiles() - 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"); +local function writefiles +( ) + 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" ) end --- test 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); +-- +-- 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 ) end - if not stat and expect then - cwriteln("failure: ",filename," should not be excluded"); - os.exit(1); + + if not stat and expect + then + cwriteln( 'failure: ', filename, ' should not be excluded' ) + os.exit( 1 ) end end -- test all files -local function testfiles() - 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); +local function testfiles +( ) + 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 ) end -cwriteln( 'testing startup excludes' ); -writefiles( ); -cwriteln( 'starting Lsyncd' ); -local pid = spawn( './lsyncd', cfgfile, '-log', 'all'); +cwriteln( 'testing startup excludes' ) + +writefiles( ) + +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 ) -cwriteln( 'testing excludes after startup' ); -testfiles( ); -cwriteln( 'ok, removing sources' ); + +cwriteln( 'testing excludes after startup' ) + +testfiles( ) + +cwriteln( 'ok, removing sources' ) if srcdir:sub( 1,4 ) ~= '/tmp' then -- just to make sure before rm -rf - cwriteln( 'exit before drama, srcdir is "', srcdir, '"' ); - os.exit( 1 ); + cwriteln( 'exit before drama, srcdir is "', srcdir, '"' ) + + os.exit( 1 ) 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 ) if result ~= 'exit' or code ~= 0 then - cwriteln( 'fail, target directory not empty!' ); - os.exit( 1 ); + cwriteln( 'fail, target directory not empty!' ) + + os.exit( 1 ) end -cwriteln( 'writing files after startup' ); -writefiles( ); -cwriteln( 'waiting for Lsyncd to transmit changes' ); -posix.sleep( 5 ); -testfiles( ); +cwriteln( 'writing files after startup' ) -cwriteln( 'killing started Lsyncd' ); -posix.kill( pid ); -local _, exitmsg, lexitcode = posix.wait( lpid ); -cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ); +writefiles( ) -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 - cwriteln( "OK" ); - os.exit( 0 ); + cwriteln( "OK" ) + + os.exit( 0 ) else - os.exit( 1 ); + os.exit( 1 ) end -- TODO remove temp