mirror of https://github.com/octoleo/lsyncd.git
fixing rsync delete
This commit is contained in:
parent
ea7a42cf39
commit
6b596553b3
102
lsyncd.lua
102
lsyncd.lua
|
@ -353,7 +353,7 @@ local Inlet, InletControl = (function()
|
||||||
-- Always includes a trailing slash.
|
-- Always includes a trailing slash.
|
||||||
--
|
--
|
||||||
pathdir = function(event)
|
pathdir = function(event)
|
||||||
return string.match(getPath(event), "^(.*/)[^/]*/?") or ""
|
return string.match(getPath(event), "^(.*/)[^/]+/?") or ""
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
@ -452,15 +452,35 @@ local Inlet, InletControl = (function()
|
||||||
--
|
--
|
||||||
local eventListFuncs = {
|
local eventListFuncs = {
|
||||||
-----
|
-----
|
||||||
-- Returns the paths of all events.
|
-- Returns a list of file/dirnames of all events in list.
|
||||||
--
|
--
|
||||||
getPaths = function(elist, delimiter)
|
getNames = function(elist)
|
||||||
local dlist = el2dl[elist]
|
local dlist = el2dl[elist]
|
||||||
if not dlist then
|
if not dlist then
|
||||||
error("cannot find delay list from event list.")
|
error("cannot find delay list from event list.")
|
||||||
end
|
end
|
||||||
if not delimiter then
|
local pl = {}
|
||||||
delimiter = '\n'
|
local i = 1
|
||||||
|
for k, d in pairs(dlist) do
|
||||||
|
if type(k) == "number" then
|
||||||
|
pl[i] = string.match(d.path, "[^/]+/?$")
|
||||||
|
i = i + 1
|
||||||
|
if d.path2 then
|
||||||
|
pl[i] = string.match(d.path2, "[^/]+/?$")
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return pl
|
||||||
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Returns a list of paths of all events in list.
|
||||||
|
--
|
||||||
|
getPaths = function(elist)
|
||||||
|
local dlist = el2dl[elist]
|
||||||
|
if not dlist then
|
||||||
|
error("cannot find delay list from event list.")
|
||||||
end
|
end
|
||||||
local pl = {}
|
local pl = {}
|
||||||
local i = 1
|
local i = 1
|
||||||
|
@ -474,20 +494,17 @@ local Inlet, InletControl = (function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.concat(pl, delimiter) .. delimiter
|
return pl
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Returns the absolute local paths of all events.
|
-- Returns a list of absolutes local paths in list.
|
||||||
--
|
--
|
||||||
getSourcePaths = function(elist, delimiter)
|
getSourcePaths = function(elist)
|
||||||
local dlist = el2dl[elist]
|
local dlist = el2dl[elist]
|
||||||
if not dlist then
|
if not dlist then
|
||||||
error("cannot find delay list from event list.")
|
error("cannot find delay list from event list.")
|
||||||
end
|
end
|
||||||
if not delimiter then
|
|
||||||
delimiter = '\n'
|
|
||||||
end
|
|
||||||
local pl = {}
|
local pl = {}
|
||||||
local i = 1
|
local i = 1
|
||||||
for k, d in pairs(dlist) do
|
for k, d in pairs(dlist) do
|
||||||
|
@ -500,7 +517,7 @@ local Inlet, InletControl = (function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.concat(pl, delimiter) .. delimiter
|
return pl
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,14 +959,18 @@ local Sync = (function()
|
||||||
-- Puts an action on the delay stack.
|
-- Puts an action on the delay stack.
|
||||||
--
|
--
|
||||||
local function delay(self, etype, time, path, path2)
|
local function delay(self, etype, time, path, path2)
|
||||||
log("Function", "delay(", self.config.name,", ",etype,", ",path,")")
|
log("Function", "delay(",self.config.name,", ",
|
||||||
|
etype,", ",path,", ",path2,")")
|
||||||
|
|
||||||
|
-- exclusion tests
|
||||||
if not path2 then
|
if not path2 then
|
||||||
-- test for exclusion
|
-- simple test for 1 path events
|
||||||
if self.excludes:test(path) then
|
if self.excludes:test(path) then
|
||||||
log("Exclude", "excluded ",etype," on '",path,"'")
|
log("Exclude", "excluded ",etype," on '",path,"'")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
-- for 2 paths (move) it might result into a split
|
||||||
log("Function", "+ ",path2)
|
log("Function", "+ ",path2)
|
||||||
local ex1 = self.excludes:test(path)
|
local ex1 = self.excludes:test(path)
|
||||||
local ex2 = self.excludes:test(path2)
|
local ex2 = self.excludes:test(path2)
|
||||||
|
@ -975,6 +996,8 @@ local Sync = (function()
|
||||||
if etype == "Move" and not self.config.onMove then
|
if etype == "Move" and not self.config.onMove then
|
||||||
-- if there is no move action defined,
|
-- if there is no move action defined,
|
||||||
-- split a move as delete/create
|
-- split a move as delete/create
|
||||||
|
-- layer 1 scripts which want moves events have to
|
||||||
|
-- set onMove simply to "true"
|
||||||
log("Delay", "splitting Move into Delete & Create")
|
log("Delay", "splitting Move into Delete & Create")
|
||||||
delay(self, "Delete", time, path, nil)
|
delay(self, "Delete", time, path, nil)
|
||||||
delay(self, "Create", time, path2, nil)
|
delay(self, "Create", time, path2, nil)
|
||||||
|
@ -1001,16 +1024,15 @@ local Sync = (function()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
|
||||||
-- detects blocks and collapses by working from back until
|
-- detects blocks and collapses by working from back until
|
||||||
-- front through the fifo
|
-- front through the fifo
|
||||||
|
|
||||||
InletControl.setSync(self)
|
InletControl.setSync(self)
|
||||||
local ne, ne2 = InletControl.d2e(nd)
|
local ne, ne2 = InletControl.d2e(nd)
|
||||||
local il = #self.delays -- last delay
|
local il = #self.delays -- last delay
|
||||||
while il > 0 do
|
while il > 0 do
|
||||||
-- get 'old' delay
|
-- get 'old' delay
|
||||||
local od = self.delays[il]
|
local od = self.delays[il]
|
||||||
-- tries to collapse identical paths
|
|
||||||
local oe, oe2 = InletControl.d2e(od)
|
local oe, oe2 = InletControl.d2e(od)
|
||||||
|
|
||||||
if oe.etype == "Blanket" then
|
if oe.etype == "Blanket" then
|
||||||
|
@ -1030,7 +1052,9 @@ local Sync = (function()
|
||||||
local c = self.config.collapse(oel, nel, self.config)
|
local c = self.config.collapse(oel, nel, self.config)
|
||||||
if c == 0 then
|
if c == 0 then
|
||||||
-- events nullificate each ether
|
-- events nullificate each ether
|
||||||
od.etype = "None"
|
log("Delay",nd.etype," and ",od.etype," on ",path,
|
||||||
|
" nullified each other.")
|
||||||
|
od.etype = "None"
|
||||||
table.remove(self.delays, il)
|
table.remove(self.delays, il)
|
||||||
return
|
return
|
||||||
elseif c == 1 then
|
elseif c == 1 then
|
||||||
|
@ -1080,7 +1104,8 @@ local Sync = (function()
|
||||||
-- there was no hit on collapse or it decided to stack.
|
-- there was no hit on collapse or it decided to stack.
|
||||||
table.insert(self.delays, nd)
|
table.insert(self.delays, nd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Returns the nearest alarm for this Sync.
|
-- Returns the nearest alarm for this Sync.
|
||||||
--
|
--
|
||||||
|
@ -1223,8 +1248,14 @@ local Sync = (function()
|
||||||
if nothing then
|
if nothing then
|
||||||
f:write(" nothing.\n")
|
f:write(" nothing.\n")
|
||||||
end
|
end
|
||||||
|
f:write("\n")
|
||||||
|
end
|
||||||
|
|
||||||
f:write("\n\n")
|
-- DEBUG delays
|
||||||
|
local _delay = delay
|
||||||
|
delay = function(self, ...)
|
||||||
|
_delay(self, ...)
|
||||||
|
statusReport(self, io.stdout)
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
@ -1426,9 +1457,6 @@ end
|
||||||
--
|
--
|
||||||
local Inotifies = (function()
|
local Inotifies = (function()
|
||||||
|
|
||||||
---- XXX wdlist, syncpaths
|
|
||||||
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- A list indexed by inotifies watch descriptor yielding the
|
-- A list indexed by inotifies watch descriptor yielding the
|
||||||
-- directories absolute paths.
|
-- directories absolute paths.
|
||||||
|
@ -1492,7 +1520,9 @@ local Inotifies = (function()
|
||||||
-- creates a Create event for entry.
|
-- creates a Create event for entry.
|
||||||
if raiseSync then
|
if raiseSync then
|
||||||
local relative = splitPath(pd, syncRoots[raiseSync])
|
local relative = splitPath(pd, syncRoots[raiseSync])
|
||||||
raiseSync:delay("Create", raiseTime, relative)
|
if relative then
|
||||||
|
raiseSync:delay("Create", raiseTime, relative)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- adds syncs for subdirs
|
-- adds syncs for subdirs
|
||||||
if isdir and recurse then
|
if isdir and recurse then
|
||||||
|
@ -2440,13 +2470,20 @@ local default_rsync = {
|
||||||
local elist = inlet.getEvents(function(e2)
|
local elist = inlet.getEvents(function(e2)
|
||||||
return e2.etype == "Delete" and evDir == e2.pathdir
|
return e2.etype == "Delete" and evDir == e2.pathdir
|
||||||
end)
|
end)
|
||||||
local paths = elist.getPaths()
|
local names = elist.getNames()
|
||||||
|
-- recursively include all subdirs/files of directories
|
||||||
|
for i, name in ipairs(names) do
|
||||||
|
if string.byte(path, -1) == 47 then
|
||||||
|
names[i] = names[i] .. "**"
|
||||||
|
end
|
||||||
|
end
|
||||||
log("Normal", "rsyncing deletes in ",evDir,":\n",paths)
|
log("Normal", "rsyncing deletes in ",evDir,":\n",paths)
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig()
|
||||||
spawn(elist, "/usr/bin/rsync",
|
spawn(elist, "/usr/bin/rsync",
|
||||||
"<", paths,
|
"<", paths,
|
||||||
|
"-vv",
|
||||||
"--delete",
|
"--delete",
|
||||||
config.rsyncOps .. "d",
|
config.rsyncOps, "-r",
|
||||||
"--include-from=-",
|
"--include-from=-",
|
||||||
"--exclude=*",
|
"--exclude=*",
|
||||||
config.source .. evDir, config.target .. evDir)
|
config.source .. evDir, config.target .. evDir)
|
||||||
|
@ -2458,7 +2495,7 @@ local default_rsync = {
|
||||||
local elist = inlet.getEvents(function(e2)
|
local elist = inlet.getEvents(function(e2)
|
||||||
return e2.etype ~= "Delete"
|
return e2.etype ~= "Delete"
|
||||||
end)
|
end)
|
||||||
local paths = elist.getPaths()
|
local paths = table.concat(elist.getPaths(), "\n")
|
||||||
log("Normal", "rsyncing a list of new/modified files/dirs\n",
|
log("Normal", "rsyncing a list of new/modified files/dirs\n",
|
||||||
paths)
|
paths)
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig()
|
||||||
|
@ -2468,7 +2505,6 @@ local default_rsync = {
|
||||||
"--files-from=-",
|
"--files-from=-",
|
||||||
config.source, config.target)
|
config.source, config.target)
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
@ -2484,9 +2520,8 @@ local default_rsync = {
|
||||||
" -> ", config.target)
|
" -> ", config.target)
|
||||||
spawn(event, "/usr/bin/rsync",
|
spawn(event, "/usr/bin/rsync",
|
||||||
"--delete",
|
"--delete",
|
||||||
config.rsyncOps .. "r",
|
config.rsyncOps, "-r",
|
||||||
config.source,
|
config.source, config.target)
|
||||||
config.target)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
@ -2529,11 +2564,11 @@ local default_rsyncssh = {
|
||||||
local elist = inlet.getEvents(function(e)
|
local elist = inlet.getEvents(function(e)
|
||||||
return e.etype ~= "Move"
|
return e.etype ~= "Move"
|
||||||
end)
|
end)
|
||||||
local spaths = elist.getPaths()
|
local paths = table.concat(elist.getPaths(), "\n")
|
||||||
log("Normal", "rsyncing list\n", spaths)
|
log("Normal", "rsyncing list\n", spaths)
|
||||||
spawn(elist, "/usr/bin/rsync",
|
spawn(elist, "/usr/bin/rsync",
|
||||||
"<", spaths,
|
"<", spaths,
|
||||||
config.rsyncOps .. "r",
|
config.rsyncOps, "r",
|
||||||
"--delete",
|
"--delete",
|
||||||
"--include-from=-",
|
"--include-from=-",
|
||||||
"--exclude=*",
|
"--exclude=*",
|
||||||
|
@ -2659,6 +2694,9 @@ default = {
|
||||||
--
|
--
|
||||||
collapse = function(event1, event2, config)
|
collapse = function(event1, event2, config)
|
||||||
if event1.path == event2.path then
|
if event1.path == event2.path then
|
||||||
|
if event1.status == "active" then
|
||||||
|
return 3
|
||||||
|
end
|
||||||
local e1 = event1.etype .. event1.move
|
local e1 = event1.etype .. event1.move
|
||||||
local e2 = event2.etype .. event2.move
|
local e2 = event2.etype .. event2.move
|
||||||
return config.collapseTable[e1][e2]
|
return config.collapseTable[e1][e2]
|
||||||
|
|
|
@ -17,7 +17,8 @@ local trgdir = tdir.."trg/"
|
||||||
posix.mkdir(srcdir)
|
posix.mkdir(srcdir)
|
||||||
posix.mkdir(trgdir)
|
posix.mkdir(trgdir)
|
||||||
--local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,"-log", "all")
|
--local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,"-log", "all")
|
||||||
local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir)
|
local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,
|
||||||
|
"-log", "Exec")
|
||||||
|
|
||||||
cwriteln("waiting for Lsyncd to startup")
|
cwriteln("waiting for Lsyncd to startup")
|
||||||
posix.sleep(1)
|
posix.sleep(1)
|
||||||
|
@ -266,6 +267,7 @@ for ai=1,20 do
|
||||||
for i, d in ipairs(dice) do
|
for i, d in ipairs(dice) do
|
||||||
if acn <= d[1] then
|
if acn <= d[1] then
|
||||||
d[2]()
|
d[2]()
|
||||||
|
posix.sleep(2)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue