mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-22 14:48:29 +00:00
fixing absolute exludes, writing an exclusion test.
This commit is contained in:
parent
d79ce6da50
commit
71bd7a2905
@ -1011,7 +1011,7 @@ local Excludes = (function()
|
|||||||
-- this was a ** before
|
-- this was a ** before
|
||||||
p = string.gsub(p, "%[%^/%]%*%[%^/%]%*", ".*")
|
p = string.gsub(p, "%[%^/%]%*%[%^/%]%*", ".*")
|
||||||
p = string.gsub(p, "^/", "^/")
|
p = string.gsub(p, "^/", "^/")
|
||||||
if p.byte(1) ~= 47 then -- does not begin with "/"
|
if p:sub(1,2) ~= "^/" then -- does not begin with "^/"
|
||||||
-- all matches should begin with "/".
|
-- all matches should begin with "/".
|
||||||
p = "/" .. p;
|
p = "/" .. p;
|
||||||
end
|
end
|
||||||
|
110
tests/exclude.lua
Executable file
110
tests/exclude.lua
Executable file
@ -0,0 +1,110 @@
|
|||||||
|
#!/usr/bin/lua
|
||||||
|
require("posix")
|
||||||
|
dofile("tests/testlib.lua")
|
||||||
|
|
||||||
|
cwriteln("****************************************************************")
|
||||||
|
cwriteln(" Testing excludes ")
|
||||||
|
cwriteln("****************************************************************")
|
||||||
|
|
||||||
|
local tdir, srcdir, trgdir = mktemps()
|
||||||
|
local logfile = tdir .. "log"
|
||||||
|
local cfgfile = tdir .. "config.lua"
|
||||||
|
local range = 5
|
||||||
|
local log = {"-log", "all"}
|
||||||
|
|
||||||
|
writefile(cfgfile, [[
|
||||||
|
settings = {
|
||||||
|
.logfile = "]]..logfile..[[",
|
||||||
|
.nodaemon = true,
|
||||||
|
.delay = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
rsync {
|
||||||
|
defaults.rsync,
|
||||||
|
source = "]]..srcdir..[[",
|
||||||
|
target = "]]..trgdir..[[",
|
||||||
|
exclude = {
|
||||||
|
"erf,
|
||||||
|
"/eaf",
|
||||||
|
"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");
|
||||||
|
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);
|
||||||
|
end
|
||||||
|
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(srcdir .. "erf", false);
|
||||||
|
testfile(srcdir .. "eaf", false);
|
||||||
|
testfile(srcdir .. "erd", true);
|
||||||
|
testfile(srcdir .. "ead", true);
|
||||||
|
testfile(srcdir .. "d/erf", false);
|
||||||
|
testfile(srcdir .. "d/eaf", true);
|
||||||
|
testfile(srcdir .. "d/erd", true);
|
||||||
|
testfile(srcdir .. "d/ead", true);
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
cwriteln("testing startup excludes");
|
||||||
|
writefiles();
|
||||||
|
cwriteln("starting Lsyncd");
|
||||||
|
local pid = spawn("./lsyncd");
|
||||||
|
cwriteln("waiting for Lsyncd to start");
|
||||||
|
posix.sleep(3)
|
||||||
|
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("exist before drama, srcdir is '", srcdir, "'");
|
||||||
|
os.exit(1);
|
||||||
|
end
|
||||||
|
os.execute("rm -rf "..srcdir.."/*");
|
||||||
|
writeln("waiting for Lsyncd to remove destination");
|
||||||
|
if os.execute("diff -urN "..srcdir.." "..trgdir) ~= 0 then
|
||||||
|
os.exit(1);
|
||||||
|
end
|
||||||
|
|
||||||
|
posix.sleep(5);
|
||||||
|
writeln("writing files after startup");
|
||||||
|
writefiles();
|
||||||
|
writeln("waiting for Lsyncd to transmit changes");
|
||||||
|
posix.sleep(5);
|
||||||
|
testfiles();
|
||||||
|
|
||||||
|
writeln("killing started Lsyncd");
|
||||||
|
posix.kill(pid);
|
||||||
|
local _, exitmsg, lexitcode = posix.wait(lpid);
|
||||||
|
cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", lexitcode);
|
||||||
|
posix.sleep(1);
|
||||||
|
if lexitcode == 0 then
|
||||||
|
cwriteln("OK");
|
||||||
|
end
|
||||||
|
os.exit(lexitcode);
|
||||||
|
|
||||||
|
-- TODO remove temp
|
@ -49,6 +49,12 @@ cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", lexitcode)
|
|||||||
posix.sleep(1)
|
posix.sleep(1)
|
||||||
|
|
||||||
cwriteln("* differences:")
|
cwriteln("* differences:")
|
||||||
os.execute("diff -urN "..srcdir.." "..trgdir)
|
exitcode = os.execute("diff -urN "..srcdir.." "..trgdir)
|
||||||
|
cwriteln("Exitcode of diff = '", exitcode, "'")
|
||||||
|
if exitcode ~= 0 then
|
||||||
|
os.exit(1)
|
||||||
|
else
|
||||||
|
os.exit(0)
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO remove temp
|
-- TODO remove temp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user