mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-09-21 03:29:02 +00:00
cleanups
This commit is contained in:
parent
2fb819d992
commit
36a13acd2b
@ -11,7 +11,7 @@ include_directories ( ${LUA_INCLUDE_DIR} )
|
|||||||
|
|
||||||
|
|
||||||
# setting Lsyncd sources
|
# setting Lsyncd sources
|
||||||
set( LSYNCD_SRC core.c luacode.c )
|
set( LSYNCD_SRC core/core.c luacode.c )
|
||||||
|
|
||||||
# tell systemd via the sd-daemon library about the status of Lsyncd
|
# tell systemd via the sd-daemon library about the status of Lsyncd
|
||||||
option( WITH_SYSTEMD "Communicate Lsyncd status to systemd" ON )
|
option( WITH_SYSTEMD "Communicate Lsyncd status to systemd" ON )
|
||||||
@ -20,9 +20,10 @@ option( WITH_SYSTEMD "Communicate Lsyncd status to systemd" ON )
|
|||||||
option( WITH_INOTIFY "Compile with inotify file notifications (Linux)" ON )
|
option( WITH_INOTIFY "Compile with inotify file notifications (Linux)" ON )
|
||||||
|
|
||||||
if( WITH_INOTIFY )
|
if( WITH_INOTIFY )
|
||||||
set( LSYNCD_SRC ${LSYNCD_SRC} inotify.c )
|
set( LSYNCD_SRC ${LSYNCD_SRC} core/inotify.c )
|
||||||
endif( WITH_INOTIFY )
|
endif( WITH_INOTIFY )
|
||||||
|
|
||||||
|
|
||||||
# generating the config.h file
|
# generating the config.h file
|
||||||
configure_file (
|
configure_file (
|
||||||
"${PROJECT_SOURCE_DIR}/config.h.in"
|
"${PROJECT_SOURCE_DIR}/config.h.in"
|
||||||
@ -32,14 +33,13 @@ include_directories("${PROJECT_BINARY_DIR}")
|
|||||||
|
|
||||||
|
|
||||||
# building and compiling the part of lsyncd written in Lua
|
# building and compiling the part of lsyncd written in Lua
|
||||||
# also called "runner"
|
|
||||||
|
|
||||||
set( LUA_CODE
|
set( LUA_CODE
|
||||||
${PROJECT_SOURCE_DIR}/lsyncd.lua
|
${PROJECT_SOURCE_DIR}/lsyncd.lua
|
||||||
${PROJECT_SOURCE_DIR}/default.lua
|
${PROJECT_SOURCE_DIR}/default/default.lua
|
||||||
${PROJECT_SOURCE_DIR}/default-rsync.lua
|
${PROJECT_SOURCE_DIR}/default/rsync.lua
|
||||||
${PROJECT_SOURCE_DIR}/default-rsyncssh.lua
|
${PROJECT_SOURCE_DIR}/default/rsyncssh.lua
|
||||||
${PROJECT_SOURCE_DIR}/default-direct.lua
|
${PROJECT_SOURCE_DIR}/default/direct.lua
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_command( OUTPUT luacode.c
|
add_custom_command( OUTPUT luacode.c
|
||||||
@ -61,6 +61,7 @@ add_custom_target( manpage
|
|||||||
DEPENDS doc/manpage/lsyncd.1.txt
|
DEPENDS doc/manpage/lsyncd.1.txt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# the test suite
|
||||||
add_custom_target( tests
|
add_custom_target( tests
|
||||||
COMMAND echo "Running the tests"
|
COMMAND echo "Running the tests"
|
||||||
COMMAND echo "Note you are expected to:"
|
COMMAND echo "Note you are expected to:"
|
||||||
|
@ -3,4 +3,3 @@
|
|||||||
|
|
||||||
/* File event notification mechanims available */
|
/* File event notification mechanims available */
|
||||||
#cmakedefine WITH_INOTIFY 1
|
#cmakedefine WITH_INOTIFY 1
|
||||||
#cmakedefine WITH_FSEVENTS 1
|
|
||||||
|
@ -18,17 +18,11 @@
|
|||||||
--
|
--
|
||||||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
if not default then
|
if not default then error( 'default not loaded' ) end
|
||||||
error('default not loaded')
|
|
||||||
end
|
|
||||||
|
|
||||||
if not default.rsync then
|
if not default.rsync then error( 'default-direct needs default.rsync loaded' ) end
|
||||||
error('default-direct (currently) needs default.rsync loaded')
|
|
||||||
end
|
|
||||||
|
|
||||||
if default.direct then
|
if default.direct then error( 'default-direct already loaded' ) end
|
||||||
error('default-direct already loaded')
|
|
||||||
end
|
|
||||||
|
|
||||||
local direct = { }
|
local direct = { }
|
||||||
|
|
||||||
@ -38,7 +32,8 @@ default.direct = direct
|
|||||||
--
|
--
|
||||||
-- known configuration parameters
|
-- known configuration parameters
|
||||||
--
|
--
|
||||||
direct.checkgauge = {
|
direct.checkgauge =
|
||||||
|
{
|
||||||
--
|
--
|
||||||
-- inherits rsync config params
|
-- inherits rsync config params
|
||||||
--
|
--
|
||||||
@ -52,19 +47,20 @@ direct.checkgauge = {
|
|||||||
--
|
--
|
||||||
-- Spawns rsync for a list of events
|
-- Spawns rsync for a list of events
|
||||||
--
|
--
|
||||||
direct.action = function(inlet)
|
direct.action =
|
||||||
|
function
|
||||||
|
(
|
||||||
|
inlet
|
||||||
|
)
|
||||||
-- gets all events ready for syncing
|
-- gets all events ready for syncing
|
||||||
local event, event2 = inlet.getEvent()
|
local event, event2 = inlet.getEvent()
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig()
|
||||||
|
|
||||||
if event.etype == 'Create' then
|
if event.etype == 'Create'
|
||||||
if event.isdir then
|
then
|
||||||
spawn(
|
if event.isdir
|
||||||
event,
|
then
|
||||||
'/bin/mkdir',
|
spawn( event, '/bin/mkdir', '--', event.targetPath )
|
||||||
'--',
|
|
||||||
event.targetPath
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
-- 'cp -t', not supported on OSX
|
-- 'cp -t', not supported on OSX
|
||||||
spawn(
|
spawn(
|
||||||
@ -76,22 +72,18 @@ direct.action = function(inlet)
|
|||||||
event.targetPathdir
|
event.targetPathdir
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
elseif event.etype == 'Modify' then
|
elseif event.etype == 'Modify'
|
||||||
if event.isdir then
|
then
|
||||||
error("Do not know how to handle 'Modify' on dirs")
|
if event.isdir
|
||||||
|
then
|
||||||
|
error( 'Do not know how to handle "Modify" on dirs' )
|
||||||
end
|
end
|
||||||
spawn(event,
|
|
||||||
'/bin/cp',
|
|
||||||
'-p',
|
|
||||||
'--',
|
|
||||||
event.sourcePath,
|
|
||||||
event.targetPathdir
|
|
||||||
)
|
|
||||||
elseif event.etype == 'Delete' then
|
|
||||||
|
|
||||||
if
|
spawn(event, '/bin/cp', '-p', '--', event.sourcePath, event.targetPathdir )
|
||||||
config.delete ~= true and
|
elseif event.etype == 'Delete'
|
||||||
config.delete ~= 'running'
|
then
|
||||||
|
if config.delete ~= true
|
||||||
|
and config.delete ~= 'running'
|
||||||
then
|
then
|
||||||
inlet.discardEvent(event)
|
inlet.discardEvent(event)
|
||||||
return
|
return
|
||||||
@ -100,36 +92,31 @@ direct.action = function(inlet)
|
|||||||
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'
|
||||||
elseif event.etype == 'Move' then
|
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
|
if config.delete ~= true
|
||||||
config.delete ~= true and
|
and config.delete ~= 'running'
|
||||||
config.delete ~= 'running'
|
|
||||||
then
|
then
|
||||||
command = '/bin/mv -- "$1" "$2"'
|
command = '/bin/mv -- "$1" "$2"'
|
||||||
end
|
end
|
||||||
|
|
||||||
spawnShell(
|
spawnShell( event, command, event.targetPath, event2.targetPath )
|
||||||
event,
|
|
||||||
command,
|
|
||||||
event.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)
|
||||||
@ -139,13 +126,18 @@ 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
|
||||||
local rc = config.rsyncExitCodes[exitcode]
|
local rc = config.rsyncExitCodes[exitcode]
|
||||||
if rc == 'ok' then
|
if rc == 'ok'
|
||||||
|
then
|
||||||
log( 'Normal', 'Startup of "',agent.source,'" finished: ', exitcode )
|
log( 'Normal', 'Startup of "',agent.source,'" finished: ', exitcode )
|
||||||
elseif rc == 'again'
|
elseif rc == 'again'
|
||||||
then
|
then
|
||||||
@ -155,14 +147,16 @@ direct.collect = function(agent, exitcode)
|
|||||||
else
|
else
|
||||||
log('Error', 'Temporary or permanent failure on startup of "',
|
log('Error', 'Temporary or permanent failure on startup of "',
|
||||||
agent.source, '". Terminating since "insist" is not set.');
|
agent.source, '". Terminating since "insist" is not set.');
|
||||||
terminate(-1) -- ERRNO
|
terminate( -1 )
|
||||||
end
|
end
|
||||||
elseif rc == 'die' then
|
elseif rc == 'die'
|
||||||
|
then
|
||||||
log( 'Error', 'Failure on startup of "',agent.source,'": ', exitcode )
|
log( 'Error', 'Failure on startup of "',agent.source,'": ', exitcode )
|
||||||
else
|
else
|
||||||
log( 'Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode )
|
log( 'Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode )
|
||||||
rc = 'die'
|
rc = 'die'
|
||||||
end
|
end
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -180,8 +174,11 @@ direct.init = default.rsync.init
|
|||||||
--
|
--
|
||||||
-- Checks the configuration.
|
-- Checks the configuration.
|
||||||
--
|
--
|
||||||
direct.prepare = function( config, level )
|
direct.prepare = function
|
||||||
|
(
|
||||||
|
config,
|
||||||
|
level
|
||||||
|
)
|
||||||
default.rsync.prepare( config, level + 1 )
|
default.rsync.prepare( config, level + 1 )
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -212,3 +209,4 @@ direct.delete = true
|
|||||||
-- than speed up.
|
-- than speed up.
|
||||||
|
|
||||||
direct.maxProcesses = 1
|
direct.maxProcesses = 1
|
||||||
|
|
15
distclean.sh
15
distclean.sh
@ -1,3 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# removes all stuff generated by cmake / make
|
# removes all stuff generated by cmake / make
|
||||||
rm -rf AdditionalInfo.txt config.h Makefile build/ CMakeCache.txt CMakeFiles/ cmake_install.cmake install_manifest.txt luacode.c *.o *.out lsyncd
|
rm -rf build/ CMakeFiles/
|
||||||
|
|
||||||
|
rm -f \
|
||||||
|
AdditionalInfo.txt \
|
||||||
|
config.h \
|
||||||
|
Makefile \
|
||||||
|
CMakeCache.txt \
|
||||||
|
cmake_install.cmake \
|
||||||
|
install_manifest.txt \
|
||||||
|
luacode.c \
|
||||||
|
*.o \
|
||||||
|
*.out \
|
||||||
|
core/*.o \
|
||||||
|
lsyncd
|
||||||
|
Loading…
Reference in New Issue
Block a user