mirror of https://github.com/octoleo/lsyncd.git
cleanups
This commit is contained in:
parent
455c68877a
commit
6d45249b6c
|
@ -32,13 +32,6 @@ local mt = { }
|
||||||
local k_nt = { }
|
local k_nt = { }
|
||||||
|
|
||||||
|
|
||||||
local assignable =
|
|
||||||
{
|
|
||||||
dpos = true,
|
|
||||||
status = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- On accessing a nil index.
|
-- On accessing a nil index.
|
||||||
--
|
--
|
||||||
|
@ -60,12 +53,7 @@ mt.__newindex = function
|
||||||
k, -- key value to assign to
|
k, -- key value to assign to
|
||||||
v -- value to assign
|
v -- value to assign
|
||||||
)
|
)
|
||||||
if not assignable[ k ]
|
error( 'Cannot assign to Delay' )
|
||||||
then
|
|
||||||
error( 'Cannot assign new key "' .. k .. '" to Delay' )
|
|
||||||
end
|
|
||||||
|
|
||||||
self[ k_nt ][ k ] = v
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,10 +100,35 @@ local function wait
|
||||||
)
|
)
|
||||||
self[ k_nt ].status = 'wait'
|
self[ k_nt ].status = 'wait'
|
||||||
|
|
||||||
self[ k_nt ].alarm = alarm
|
if alarm ~= nil then self[ k_nt ].alarm = alarm end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Puts this delay as replacement on a queue.
|
||||||
|
--
|
||||||
|
local function replaceAt
|
||||||
|
(
|
||||||
|
self,
|
||||||
|
queue,
|
||||||
|
dpos
|
||||||
|
)
|
||||||
|
queue:replace( dpos, self )
|
||||||
|
self[ k_nt ].dpos = dpos
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Pushes this delay on a queue and remembers the position.
|
||||||
|
--
|
||||||
|
local function pushOn
|
||||||
|
(
|
||||||
|
self,
|
||||||
|
queue
|
||||||
|
)
|
||||||
|
self[ k_nt ].dpos = queue:push( nd )
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Creates a new delay.
|
-- Creates a new delay.
|
||||||
--
|
--
|
||||||
|
@ -135,6 +148,8 @@ local function new
|
||||||
blockedBy = blockedBy,
|
blockedBy = blockedBy,
|
||||||
setActive = setActive,
|
setActive = setActive,
|
||||||
wait = wait,
|
wait = wait,
|
||||||
|
replaceAt = replaceAt,
|
||||||
|
pushOn = pushOn,
|
||||||
[ k_nt ] =
|
[ k_nt ] =
|
||||||
{
|
{
|
||||||
etype = etype,
|
etype = etype,
|
||||||
|
|
|
@ -59,7 +59,7 @@ local function removeDelay
|
||||||
then
|
then
|
||||||
for _, vd in pairs( delay.blocks )
|
for _, vd in pairs( delay.blocks )
|
||||||
do
|
do
|
||||||
vd.status = 'wait'
|
vd:wait( )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -364,7 +364,7 @@ local function delay
|
||||||
|
|
||||||
if #self.delays > 0 then stack( self.delays:last( ), nd ) end
|
if #self.delays > 0 then stack( self.delays:last( ), nd ) end
|
||||||
|
|
||||||
nd.dpos = self.delays:push( nd )
|
nd:pushOn( self.delay )
|
||||||
|
|
||||||
recurse( )
|
recurse( )
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ local function delay
|
||||||
then
|
then
|
||||||
stack( od, nd )
|
stack( od, nd )
|
||||||
|
|
||||||
nd.dpos = self.delays:push( nd )
|
nd:pushOn( self.delays)
|
||||||
elseif ac == 'toDelete,stack'
|
elseif ac == 'toDelete,stack'
|
||||||
then
|
then
|
||||||
if od.status ~= 'active'
|
if od.status ~= 'active'
|
||||||
|
@ -397,9 +397,7 @@ local function delay
|
||||||
-- turns old delay into a delete
|
-- turns old delay into a delete
|
||||||
local rd = Delay.new( 'Delete', self, od.alarm, od.path )
|
local rd = Delay.new( 'Delete', self, od.alarm, od.path )
|
||||||
|
|
||||||
self.delays:replace( il, rd )
|
rd:replaceAn( self.delays, il )
|
||||||
|
|
||||||
rd.dpos = il
|
|
||||||
|
|
||||||
-- and stacks delay2
|
-- and stacks delay2
|
||||||
stack( rd, nd )
|
stack( rd, nd )
|
||||||
|
@ -408,7 +406,7 @@ local function delay
|
||||||
stack( od, nd )
|
stack( od, nd )
|
||||||
end
|
end
|
||||||
|
|
||||||
nd.dpos = self.delays:push( nd )
|
nd.pushOn( self.delays )
|
||||||
elseif ac == 'absorb'
|
elseif ac == 'absorb'
|
||||||
then
|
then
|
||||||
-- nada
|
-- nada
|
||||||
|
@ -416,13 +414,11 @@ local function delay
|
||||||
then
|
then
|
||||||
if od.status ~= 'active'
|
if od.status ~= 'active'
|
||||||
then
|
then
|
||||||
self.delays:replace( il, nd )
|
nd:replaceAt( self.delays, il )
|
||||||
|
|
||||||
nd.dpos = il
|
|
||||||
else
|
else
|
||||||
stack( od, nd )
|
stack( od, nd )
|
||||||
|
|
||||||
nd.dpos = self.delays:push( nd )
|
nd:pushOn( self.delays )
|
||||||
end
|
end
|
||||||
elseif ac == 'split'
|
elseif ac == 'split'
|
||||||
then
|
then
|
||||||
|
@ -449,7 +445,7 @@ local function delay
|
||||||
end
|
end
|
||||||
|
|
||||||
-- no block or combo
|
-- no block or combo
|
||||||
nd.dpos = self.delays:push( nd )
|
nd:pushOn( self.delays )
|
||||||
|
|
||||||
recurse( )
|
recurse( )
|
||||||
end
|
end
|
||||||
|
@ -472,10 +468,7 @@ local function getAlarm
|
||||||
-- finds the nearest delay waiting to be spawned
|
-- finds the nearest delay waiting to be spawned
|
||||||
for _, d in self.delays:qpairs( )
|
for _, d in self.delays:qpairs( )
|
||||||
do
|
do
|
||||||
if d.status == 'wait'
|
if d.status == 'wait' then return d.alarm end
|
||||||
then
|
|
||||||
return d.alarm
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- nothing to spawn
|
-- nothing to spawn
|
||||||
|
@ -636,7 +629,7 @@ local function addBlanketDelay
|
||||||
)
|
)
|
||||||
local newd = Delay.new( 'Blanket', self, true, '' )
|
local newd = Delay.new( 'Blanket', self, true, '' )
|
||||||
|
|
||||||
newd.dpos = self.delays:push( newd )
|
newd:pushOn( self.delays:push( newd ) )
|
||||||
|
|
||||||
return newd
|
return newd
|
||||||
end
|
end
|
||||||
|
@ -652,7 +645,7 @@ local function addInitDelay
|
||||||
)
|
)
|
||||||
local newd = Delay.new( 'Init', self, true, '' )
|
local newd = Delay.new( 'Init', self, true, '' )
|
||||||
|
|
||||||
newd.dpos = self.delays:push( newd )
|
newd:pushOn( self.delays:push( newd ) )
|
||||||
|
|
||||||
return newd
|
return newd
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue