mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-05-29 06:30:46 +00:00
further structering mantle
This commit is contained in:
parent
2f1a1967ab
commit
c7bf9fe645
|
@ -50,7 +50,7 @@ set( LUA_CODE
|
|||
${PROJECT_SOURCE_DIR}/mantle/fwriter.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/statusfile.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/useralarm.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/lsyncd.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/mci.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/user.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/string.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/wrapup.lua
|
||||
|
|
|
@ -610,7 +610,7 @@ local inletFuncs =
|
|||
(
|
||||
sync
|
||||
)
|
||||
return d2e( sync:getNextDelay( now( ) ) )
|
||||
return d2e( sync:getNextDelay( core.now( ) ) )
|
||||
end,
|
||||
|
||||
--
|
||||
|
|
|
@ -122,7 +122,7 @@ local function addWatch
|
|||
wdpaths[ wd ] = path
|
||||
|
||||
-- registers and adds watches for all subdirectories
|
||||
local entries = core.readdir( path )
|
||||
local entries = readdir( path )
|
||||
|
||||
if not entries then return end
|
||||
|
||||
|
|
|
@ -23,22 +23,9 @@ end
|
|||
|
||||
|
||||
--
|
||||
-- Safes mantle stuff wrapped away from user scripts
|
||||
--
|
||||
local core = core
|
||||
local lockGlobals = lockGlobals
|
||||
local Inotify = Inotify
|
||||
local Array = Array
|
||||
local Queue = Queue
|
||||
local Combiner = Combiner
|
||||
local Delay = Delay
|
||||
local InletFactory = InletFactory
|
||||
local Filter = Filter
|
||||
|
||||
|
||||
--
|
||||
-- Shortcuts (which user is supposed to be able to use them as well)
|
||||
-- Shortcuts
|
||||
--
|
||||
configure = core.configure
|
||||
log = core.log
|
||||
terminate = core.terminate
|
||||
now = core.now
|
||||
|
@ -450,17 +437,17 @@ function mci.initialize( firstTime )
|
|||
|
||||
if uSettings.logfile
|
||||
then
|
||||
core.configure( 'logfile', uSettings.logfile )
|
||||
configure( 'logfile', uSettings.logfile )
|
||||
end
|
||||
|
||||
if uSettings.logident
|
||||
then
|
||||
core.configure( 'logident', uSettings.logident )
|
||||
configure( 'logident', uSettings.logident )
|
||||
end
|
||||
|
||||
if uSettings.logfacility
|
||||
then
|
||||
core.configure( 'logfacility', uSettings.logfacility )
|
||||
configure( 'logfacility', uSettings.logfacility )
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -481,7 +468,7 @@ function mci.initialize( firstTime )
|
|||
-- from now on use logging as configured instead of stdout/err.
|
||||
lsyncdStatus = 'run';
|
||||
|
||||
core.configure( 'running' );
|
||||
configure( 'running' );
|
||||
|
||||
local ufuncs =
|
||||
{
|
||||
|
@ -663,230 +650,3 @@ function mci.term
|
|||
|
||||
end
|
||||
|
||||
|
||||
--============================================================================
|
||||
-- Lsyncd runner's user interface
|
||||
--============================================================================
|
||||
|
||||
|
||||
--
|
||||
-- Main utility to create new observations.
|
||||
--
|
||||
-- Returns an Inlet to that sync.
|
||||
--
|
||||
function sync
|
||||
(
|
||||
opts
|
||||
)
|
||||
if lsyncdStatus ~= 'init'
|
||||
then
|
||||
error( 'Sync can only be created during initialization.', 2 )
|
||||
end
|
||||
|
||||
return SyncMaster.add( opts ).inlet
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Spawns a new child process.
|
||||
--
|
||||
function spawn
|
||||
(
|
||||
agent, -- the reason why a process is spawned.
|
||||
-- a delay or delay list for a sync
|
||||
-- it will mark the related files as blocked.
|
||||
binary, -- binary to call
|
||||
... -- arguments
|
||||
)
|
||||
if agent == nil
|
||||
or type( agent ) ~= 'table'
|
||||
then
|
||||
error( 'spawning with an invalid agent', 2 )
|
||||
end
|
||||
|
||||
if lsyncdStatus == 'fade'
|
||||
then
|
||||
log( 'Normal', 'ignored process spawning while fading' )
|
||||
return
|
||||
end
|
||||
|
||||
if type( binary ) ~= 'string'
|
||||
then
|
||||
error( 'calling spawn(agent, binary, ...): binary is not a string', 2 )
|
||||
end
|
||||
|
||||
local dol = InletFactory.getDelayOrList( agent )
|
||||
|
||||
if not dol
|
||||
then
|
||||
error( 'spawning with an unknown agent', 2 )
|
||||
end
|
||||
|
||||
--
|
||||
-- checks if a spawn is called on an already active event
|
||||
--
|
||||
if dol.status
|
||||
then
|
||||
-- is an event
|
||||
|
||||
if dol.status ~= 'wait'
|
||||
then
|
||||
error( 'spawn() called on an non-waiting event', 2 )
|
||||
end
|
||||
else
|
||||
-- is a list
|
||||
for _, d in ipairs( dol )
|
||||
do
|
||||
if d.status ~= 'wait'
|
||||
and d.status ~= 'block'
|
||||
then
|
||||
error( 'spawn() called on an non-waiting event list', 2 )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- tries to spawn the process
|
||||
--
|
||||
local pid = core.exec( binary, ... )
|
||||
|
||||
if pid and pid > 0
|
||||
then
|
||||
processCount = processCount + 1
|
||||
|
||||
if uSettings.maxProcesses
|
||||
and processCount > uSettings.maxProcesses
|
||||
then
|
||||
error( 'Spawned too much processes!' )
|
||||
end
|
||||
|
||||
local sync = InletFactory.getSync( agent )
|
||||
|
||||
-- delay or list
|
||||
if dol.status
|
||||
then
|
||||
-- is a delay
|
||||
dol:setActive( )
|
||||
|
||||
sync.processes[ pid ] = dol
|
||||
else
|
||||
-- is a list
|
||||
for _, d in ipairs( dol )
|
||||
do
|
||||
d:setActive( )
|
||||
end
|
||||
|
||||
sync.processes[ pid ] = dol
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Spawns a child process using the default shell.
|
||||
--
|
||||
function spawnShell
|
||||
(
|
||||
agent, -- the delay(list) to spawn the command for
|
||||
command, -- the shell command
|
||||
... -- additonal arguments
|
||||
)
|
||||
return spawn( agent, '/bin/sh', '-c', command, '/bin/sh', ... )
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Observes a filedescriptor.
|
||||
--
|
||||
function observefd
|
||||
(
|
||||
fd, -- file descriptor
|
||||
ready, -- called when fd is ready to be read
|
||||
writey -- called when fd is ready to be written
|
||||
)
|
||||
return core.observe_fd( fd, ready, writey )
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Stops observeing a filedescriptor.
|
||||
--
|
||||
function nonobservefd
|
||||
(
|
||||
fd -- file descriptor
|
||||
)
|
||||
return core.nonobserve_fd( fd )
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Calls func at timestamp.
|
||||
--
|
||||
-- Use now() to receive current timestamp
|
||||
-- add seconds with '+' to it
|
||||
--
|
||||
alarm = UserAlarms.alarm
|
||||
|
||||
|
||||
--
|
||||
-- Comfort routine, also for user.
|
||||
-- Returns true if 'str' starts with 'Start'
|
||||
--
|
||||
function string.starts
|
||||
(
|
||||
str,
|
||||
Start
|
||||
)
|
||||
return string.sub( str, 1, #Start ) == Start
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Comfort routine, also for user.
|
||||
-- Returns true if 'str' ends with 'End'
|
||||
--
|
||||
function string.ends
|
||||
(
|
||||
str,
|
||||
End
|
||||
)
|
||||
return End == '' or string.sub( str, -#End ) == End
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- The settings call
|
||||
--
|
||||
function settings
|
||||
(
|
||||
a1 -- a string for getting a setting
|
||||
-- or a table of key/value pairs to set these settings
|
||||
)
|
||||
|
||||
-- if a1 is a string this is a get operation
|
||||
if type( a1 ) == 'string'
|
||||
then
|
||||
return uSettings[ a1 ]
|
||||
end
|
||||
|
||||
-- if its a table it sets all the value of the bale
|
||||
for k, v in pairs( a1 )
|
||||
do
|
||||
if type( k ) ~= 'number'
|
||||
then
|
||||
if not settingsCheckgauge[ k ]
|
||||
then
|
||||
error( 'setting "'..k..'" unknown.', 2 )
|
||||
end
|
||||
|
||||
uSettings[ k ] = v
|
||||
else
|
||||
if not settingsCheckgauge[ v ]
|
||||
then
|
||||
error( 'setting "'..v..'" unknown.', 2 )
|
||||
end
|
||||
|
||||
uSettings[ v ] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -56,7 +56,7 @@ userENV =
|
|||
sync = sync,
|
||||
|
||||
-- lsyncd core available to user scripts
|
||||
log = log,
|
||||
log = core.log,
|
||||
nonobservefs = core.nonobserfd,
|
||||
now = core.now,
|
||||
observefd = core.observefd,
|
||||
|
|
Loading…
Reference in New Issue
Block a user