mirror of https://github.com/octoleo/lsyncd.git
allow true, false, 'running' and 'startup' for the delete parameter
This commit is contained in:
parent
a82f4da7cd
commit
5f01a04335
|
@ -83,29 +83,48 @@ direct.action = function(inlet)
|
||||||
event.targetPathdir
|
event.targetPathdir
|
||||||
)
|
)
|
||||||
elseif event.etype == 'Delete' then
|
elseif event.etype == 'Delete' then
|
||||||
if not config.delete then
|
|
||||||
|
if
|
||||||
|
config.delete ~= true and
|
||||||
|
config.delete ~= 'running'
|
||||||
|
then
|
||||||
inlet.discardEvent(event)
|
inlet.discardEvent(event)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tp = event.targetPath
|
local tp = event.targetPath
|
||||||
|
|
||||||
-- extra security check
|
-- extra security check
|
||||||
if tp == '' or tp == '/' or not tp then
|
if tp == '' or tp == '/' or not tp then
|
||||||
error('Refusing to erase your harddisk!')
|
error('Refusing to erase your harddisk!')
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn(event, '/bin/rm', '-rf', tp)
|
spawn(event, '/bin/rm', '-rf', tp)
|
||||||
|
|
||||||
elseif event.etype == 'Move' then
|
elseif event.etype == 'Move' then
|
||||||
local tp = event.targetPath
|
local tp = event.targetPath
|
||||||
|
|
||||||
-- extra security check
|
-- extra security check
|
||||||
if tp == '' or tp == '/' or not tp then
|
if tp == '' or tp == '/' or not tp then
|
||||||
error('Refusing to erase your harddisk!')
|
error('Refusing to erase your harddisk!')
|
||||||
end
|
end
|
||||||
|
|
||||||
local command = '/bin/mv $1 $2 || /bin/rm -rf $1'
|
local command = '/bin/mv $1 $2 || /bin/rm -rf $1'
|
||||||
if not config.delete then command = '/bin/mv $1 $2'; end
|
|
||||||
|
if
|
||||||
|
config.delete ~= true and
|
||||||
|
config.delete ~= 'running'
|
||||||
|
then
|
||||||
|
command = '/bin/mv $1 $2'
|
||||||
|
end
|
||||||
|
|
||||||
spawnShell(
|
spawnShell(
|
||||||
event,
|
event,
|
||||||
command,
|
command,
|
||||||
event.targetPath,
|
event.targetPath,
|
||||||
event2.targetPath)
|
event2.targetPath
|
||||||
|
)
|
||||||
|
|
||||||
else
|
else
|
||||||
log('Warn', 'ignored an event of type "',event.etype, '"')
|
log('Warn', 'ignored an event of type "',event.etype, '"')
|
||||||
inlet.discardEvent(event)
|
inlet.discardEvent(event)
|
||||||
|
@ -116,6 +135,7 @@ end
|
||||||
-- Called when collecting a finished child process
|
-- Called when collecting a finished child process
|
||||||
--
|
--
|
||||||
direct.collect = function(agent, exitcode)
|
direct.collect = function(agent, exitcode)
|
||||||
|
|
||||||
local config = agent.config
|
local config = agent.config
|
||||||
|
|
||||||
if not agent.isList and agent.etype == 'Init' then
|
if not agent.isList and agent.etype == 'Init' then
|
||||||
|
|
|
@ -192,7 +192,7 @@ rsync.action = function( inlet )
|
||||||
local config = inlet.getConfig( )
|
local config = inlet.getConfig( )
|
||||||
local delete = nil
|
local delete = nil
|
||||||
|
|
||||||
if config.delete then
|
if config.delete == true or config.delete == 'running' then
|
||||||
delete = { '--delete', '--ignore-errors' }
|
delete = { '--delete', '--ignore-errors' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ rsync.init = function(event)
|
||||||
target = config.host .. ':' .. config.targetdir
|
target = config.host .. ':' .. config.targetdir
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.delete then
|
if config.delete == true or config.delete == 'startup' then
|
||||||
delete = { '--delete', '--ignore-errors' }
|
delete = { '--delete', '--ignore-errors' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,11 @@ rsyncssh.action = function( inlet )
|
||||||
-- instead of constructing rsync filters
|
-- instead of constructing rsync filters
|
||||||
|
|
||||||
if event.etype == 'Delete' then
|
if event.etype == 'Delete' then
|
||||||
if not config.delete then
|
|
||||||
|
if
|
||||||
|
config.delete ~= true and
|
||||||
|
config.delete ~= 'running'
|
||||||
|
then
|
||||||
inlet.discardEvent(event)
|
inlet.discardEvent(event)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue