mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-15 14:42:23 +00:00
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
|
||||
)
|
||||
elseif event.etype == 'Delete' then
|
||||
if not config.delete then
|
||||
|
||||
if
|
||||
config.delete ~= true and
|
||||
config.delete ~= 'running'
|
||||
then
|
||||
inlet.discardEvent(event)
|
||||
return
|
||||
end
|
||||
|
||||
local tp = event.targetPath
|
||||
|
||||
-- extra security check
|
||||
if tp == '' or tp == '/' or not tp then
|
||||
error('Refusing to erase your harddisk!')
|
||||
end
|
||||
|
||||
spawn(event, '/bin/rm', '-rf', tp)
|
||||
|
||||
elseif event.etype == 'Move' then
|
||||
local tp = event.targetPath
|
||||
|
||||
-- extra security check
|
||||
if tp == '' or tp == '/' or not tp then
|
||||
error('Refusing to erase your harddisk!')
|
||||
end
|
||||
|
||||
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(
|
||||
event,
|
||||
command,
|
||||
event.targetPath,
|
||||
event2.targetPath)
|
||||
event2.targetPath
|
||||
)
|
||||
|
||||
else
|
||||
log('Warn', 'ignored an event of type "',event.etype, '"')
|
||||
inlet.discardEvent(event)
|
||||
|
@ -116,6 +135,7 @@ end
|
|||
-- Called when collecting a finished child process
|
||||
--
|
||||
direct.collect = function(agent, exitcode)
|
||||
|
||||
local config = agent.config
|
||||
|
||||
if not agent.isList and agent.etype == 'Init' then
|
||||
|
|
|
@ -192,7 +192,7 @@ rsync.action = function( inlet )
|
|||
local config = inlet.getConfig( )
|
||||
local delete = nil
|
||||
|
||||
if config.delete then
|
||||
if config.delete == true or config.delete == 'running' then
|
||||
delete = { '--delete', '--ignore-errors' }
|
||||
end
|
||||
|
||||
|
@ -233,7 +233,7 @@ rsync.init = function(event)
|
|||
target = config.host .. ':' .. config.targetdir
|
||||
end
|
||||
|
||||
if config.delete then
|
||||
if config.delete == true or config.delete == 'startup' then
|
||||
delete = { '--delete', '--ignore-errors' }
|
||||
end
|
||||
|
||||
|
|
|
@ -93,7 +93,11 @@ rsyncssh.action = function( inlet )
|
|||
-- instead of constructing rsync filters
|
||||
|
||||
if event.etype == 'Delete' then
|
||||
if not config.delete then
|
||||
|
||||
if
|
||||
config.delete ~= true and
|
||||
config.delete ~= 'running'
|
||||
then
|
||||
inlet.discardEvent(event)
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user