diff --git a/CMakeLists.txt b/CMakeLists.txt index cece12b..f00559c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,14 +87,16 @@ add_custom_target( manpage ) # create_symlink( ${CMAKE_SOURCE_DIR}/tests tests) -ADD_CUSTOM_TARGET(add_tests ALL - COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/tests tests) +ADD_CUSTOM_TARGET(prepare_tests ALL + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/tests tests +) add_custom_target( tests COMMAND echo "Running the tests" COMMAND echo "Note you are expected to:" COMMAND echo " * have lua-posix installed" COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/setup.lua + COMMAND ${CMAKE_BINARY_DIR}/lsyncd -log all -script ${CMAKE_SOURCE_DIR}/tests/utils_test.lua COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/schedule.lua COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/l4rsyncdata.lua COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/filter-rsync.lua @@ -105,7 +107,7 @@ add_custom_target( tests COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-direct.lua COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/teardown.lua COMMAND echo "Finished all successfull!" - DEPENDS add_tests + DEPENDS prepare_tests ) # compiling and linking it all together diff --git a/lsyncd.lua b/lsyncd.lua index 3c9a75a..6690a9a 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -3449,6 +3449,35 @@ local function splitPath end end +function splitQuotedString + ( + text + ) + local spat, epat, buf, quoted = [=[^(['"])]=], [=[(['"])$]=] + local rv = {} + for str in text:gmatch("%S+") do + local squoted = str:match(spat) + local equoted = str:match(epat) + local escaped = str:match([=[(\*)['"]$]=]) + if squoted and not quoted and not equoted then + buf, quoted = str, squoted + elseif buf and equoted == quoted and #escaped % 2 == 0 then + str, buf, quoted = buf .. ' ' .. str, nil, nil + elseif buf then + buf = buf .. ' ' .. str + end + if not buf + then + table.insert(rv, (str:gsub(spat,""):gsub(epat,""))) + end + end + if buf + then + print("Missing matching quote for "..buf) + end + return rv +end + -- -- Interface to inotify. -- @@ -4616,6 +4645,7 @@ OPTIONS: -nodaemon Does not detach and logs to stdout/stderr -pidfile FILE Writes Lsyncds PID into FILE -runner FILE Loads Lsyncds lua part from FILE + -sshopts Additional ssh command options when using rsyncssh -version Prints versions and exits LICENSE: @@ -4740,7 +4770,18 @@ function runner.configure( args, monitors ) end }, - rsync = + sshopts = + { + 1, + function + ( + options + ) + clSettings.ssh_extras = splitQuotedString(options) + end + }, + + rsync = { 2, function @@ -4946,12 +4987,17 @@ function runner.initialize( firstTime ) } elseif s[ 1 ] == 'rsyncssh' then - sync{ + local opts = { default.rsyncssh, source = s[ 2 ], host = s[ 3 ], targetdir=s[ 4 ] } + if clSettings.ssh_extras ~= nil + then + opts.ssh = {_extra = clSettings.ssh_extras} + end + sync(opts) elseif s[ 1 ] == 'direct' then sync{ diff --git a/tests/testlib.lua b/tests/testlib.lua index 6255e03..e976f2e 100644 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -559,4 +559,35 @@ function churn end end +-- check if tables are equal +function isTableEqual(o1, o2, ignore_mt) + if o1 == o2 then return true end + local o1Type = type(o1) + local o2Type = type(o2) + if o1Type ~= o2Type then return false end + if o1Type ~= 'table' then return false end + + if not ignore_mt then + local mt1 = getmetatable(o1) + if mt1 and mt1.__eq then + --compare using built in method + return o1 == o2 + end + end + + local keySet = {} + + for key1, value1 in pairs(o1) do + local value2 = o2[key1] + if value2 == nil or isTableEqual(value1, value2, ignore_mt) == false then + return false + end + keySet[key1] = true + end + + for key2, _ in pairs(o2) do + if not keySet[key2] then return false end + end + return true +end diff --git a/tests/utils_test.lua b/tests/utils_test.lua new file mode 100644 index 0000000..c7e6942 --- /dev/null +++ b/tests/utils_test.lua @@ -0,0 +1,12 @@ +dofile( 'tests/testlib.lua' ) + +cwriteln( '****************************************************************' ) +cwriteln( ' Testing Utils Functions ' ) +cwriteln( '****************************************************************' ) + +assert(isTableEqual( + splitQuotedString("-p 22 -i '/home/test/bla blu/id_rsa'"), + {"-p", "22", "-i", "/home/test/bla blu/id_rsa"} +)) + +os.exit(0) \ No newline at end of file