mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-23 07:08:33 +00:00
removed e2s to reduce weak tables logic complexity
This commit is contained in:
parent
8ad858f95a
commit
8ff50c0a48
49
lsyncd.lua
49
lsyncd.lua
@ -305,13 +305,17 @@ local Delay = (function()
|
|||||||
--
|
--
|
||||||
-- @params see below
|
-- @params see below
|
||||||
--
|
--
|
||||||
local function new(etype, alarm, path, path2)
|
local function new(etype, sync, alarm, path, path2)
|
||||||
local o = {
|
local o = {
|
||||||
-----
|
-----
|
||||||
-- Type of event.
|
-- Type of event.
|
||||||
-- Can be 'Create', 'Modify', 'Attrib', 'Delete' and 'Move'
|
-- Can be 'Create', 'Modify', 'Attrib', 'Delete' and 'Move'
|
||||||
etype = etype,
|
etype = etype,
|
||||||
|
|
||||||
|
------
|
||||||
|
-- Sync this delay belongs to
|
||||||
|
sync = sync,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Latest point in time this should be catered for.
|
-- Latest point in time this should be catered for.
|
||||||
-- This value is in kernel ticks, return of the C's
|
-- This value is in kernel ticks, return of the C's
|
||||||
@ -328,7 +332,6 @@ local Delay = (function()
|
|||||||
------
|
------
|
||||||
-- only not nil for 'Move's.
|
-- only not nil for 'Move's.
|
||||||
-- path and file/dirname of a move destination.
|
-- path and file/dirname of a move destination.
|
||||||
--
|
|
||||||
path2 = path2,
|
path2 = path2,
|
||||||
|
|
||||||
------
|
------
|
||||||
@ -340,7 +343,6 @@ local Delay = (function()
|
|||||||
-- visible as all references should be droped on
|
-- visible as all references should be droped on
|
||||||
-- collection, nevertheless seperat status for
|
-- collection, nevertheless seperat status for
|
||||||
-- insurrance.
|
-- insurrance.
|
||||||
--
|
|
||||||
status = 'wait',
|
status = 'wait',
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -523,11 +525,8 @@ local InletFactory = (function()
|
|||||||
-- table to receive the delay of an event.
|
-- table to receive the delay of an event.
|
||||||
-- or the delay list of an event list.
|
-- or the delay list of an event list.
|
||||||
local e2d = {}
|
local e2d = {}
|
||||||
-- table to receive the sync of an event or event list
|
|
||||||
local e2s = {}
|
|
||||||
-- dont stop the garbage collector to remove entries.
|
-- dont stop the garbage collector to remove entries.
|
||||||
setmetatable(e2d, { __mode = 'v' })
|
setmetatable(e2d, { __mode = 'v' })
|
||||||
setmetatable(e2s, { __mode = 'kv' })
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- removes the trailing slash from a path
|
-- removes the trailing slash from a path
|
||||||
@ -558,14 +557,14 @@ local InletFactory = (function()
|
|||||||
-- TODO give user a readonly version.
|
-- TODO give user a readonly version.
|
||||||
--
|
--
|
||||||
config = function(event)
|
config = function(event)
|
||||||
return e2s[event].config
|
return e2d[event].sync.config
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Returns the inlet belonging to an event.
|
-- Returns the inlet belonging to an event.
|
||||||
--
|
--
|
||||||
inlet = function(event)
|
inlet = function(event)
|
||||||
return e2s[event].inlet
|
return e2d[event].sync.inlet
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -644,7 +643,7 @@ local InletFactory = (function()
|
|||||||
-- All symlinks will have been resolved.
|
-- All symlinks will have been resolved.
|
||||||
--
|
--
|
||||||
source = function(event)
|
source = function(event)
|
||||||
return e2s[event].source
|
return e2d[event].sync.source
|
||||||
end,
|
end,
|
||||||
|
|
||||||
------
|
------
|
||||||
@ -652,7 +651,7 @@ local InletFactory = (function()
|
|||||||
-- Includes a trailing slash for dirs.
|
-- Includes a trailing slash for dirs.
|
||||||
--
|
--
|
||||||
sourcePath = function(event)
|
sourcePath = function(event)
|
||||||
return e2s[event].source .. getPath(event)
|
return e2d[event].sync.source .. getPath(event)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
------
|
------
|
||||||
@ -660,7 +659,7 @@ local InletFactory = (function()
|
|||||||
-- Includes a trailing slash.
|
-- Includes a trailing slash.
|
||||||
--
|
--
|
||||||
sourcePathdir = function(event)
|
sourcePathdir = function(event)
|
||||||
return e2s[event].source ..
|
return e2d[event].sync.source ..
|
||||||
(string.match(getPath(event), '^(.*/)[^/]+/?') or '')
|
(string.match(getPath(event), '^(.*/)[^/]+/?') or '')
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -669,7 +668,7 @@ local InletFactory = (function()
|
|||||||
-- Excludes a trailing slash for dirs.
|
-- Excludes a trailing slash for dirs.
|
||||||
--
|
--
|
||||||
sourcePathname = function(event)
|
sourcePathname = function(event)
|
||||||
return e2s[event].source .. cutSlash(getPath(event))
|
return e2d[event].sync.source .. cutSlash(getPath(event))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
------
|
------
|
||||||
@ -680,7 +679,7 @@ local InletFactory = (function()
|
|||||||
-- existance of 'target', this is up to the scripts.)
|
-- existance of 'target', this is up to the scripts.)
|
||||||
--
|
--
|
||||||
target = function(event)
|
target = function(event)
|
||||||
return e2s[event].config.target
|
return e2d[event].sync.config.target
|
||||||
end,
|
end,
|
||||||
|
|
||||||
------
|
------
|
||||||
@ -688,7 +687,7 @@ local InletFactory = (function()
|
|||||||
-- Includes a trailing slash for dirs.
|
-- Includes a trailing slash for dirs.
|
||||||
--
|
--
|
||||||
targetPath = function(event)
|
targetPath = function(event)
|
||||||
return e2s[event].config.target .. getPath(event)
|
return e2d[event].sync.config.target .. getPath(event)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
------
|
------
|
||||||
@ -696,7 +695,7 @@ local InletFactory = (function()
|
|||||||
-- Includes a trailing slash.
|
-- Includes a trailing slash.
|
||||||
--
|
--
|
||||||
targetPathdir = function(event)
|
targetPathdir = function(event)
|
||||||
return e2s[event].config.target ..
|
return e2d[event].sync.config.target ..
|
||||||
(string.match(getPath(event), '^(.*/)[^/]+/?') or '')
|
(string.match(getPath(event), '^(.*/)[^/]+/?') or '')
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -705,7 +704,7 @@ local InletFactory = (function()
|
|||||||
-- Excludes a trailing slash for dirs.
|
-- Excludes a trailing slash for dirs.
|
||||||
--
|
--
|
||||||
targetPathname = function(event)
|
targetPathname = function(event)
|
||||||
return e2s[event].config.target ..
|
return e2d[event].sync.config.target ..
|
||||||
cutSlash(getPath(event))
|
cutSlash(getPath(event))
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
@ -770,7 +769,7 @@ local InletFactory = (function()
|
|||||||
__index = function(elist, func)
|
__index = function(elist, func)
|
||||||
if func == 'isList' then return true end
|
if func == 'isList' then return true end
|
||||||
|
|
||||||
if func == 'config' then return e2s[elist].config end
|
if func == 'config' then return e2d[elist].sync.config end
|
||||||
|
|
||||||
local f = eventListFuncs[func]
|
local f = eventListFuncs[func]
|
||||||
if not f then
|
if not f then
|
||||||
@ -801,7 +800,6 @@ local InletFactory = (function()
|
|||||||
delay.event = event
|
delay.event = event
|
||||||
setmetatable(event, eventMeta)
|
setmetatable(event, eventMeta)
|
||||||
e2d[event] = delay
|
e2d[event] = delay
|
||||||
e2s[event] = sync
|
|
||||||
end
|
end
|
||||||
return delay.event
|
return delay.event
|
||||||
else
|
else
|
||||||
@ -816,8 +814,6 @@ local InletFactory = (function()
|
|||||||
setmetatable(event2, eventMeta)
|
setmetatable(event2, eventMeta)
|
||||||
e2d[delay.event] = delay
|
e2d[delay.event] = delay
|
||||||
e2d[delay.event2] = delay
|
e2d[delay.event2] = delay
|
||||||
e2s[delay.event] = sync
|
|
||||||
e2s[delay.event2] = sync
|
|
||||||
|
|
||||||
-- move events have a field 'move'
|
-- move events have a field 'move'
|
||||||
event.move = 'Fr'
|
event.move = 'Fr'
|
||||||
@ -836,7 +832,6 @@ local InletFactory = (function()
|
|||||||
dlist.elist = elist
|
dlist.elist = elist
|
||||||
setmetatable(elist, eventListMeta)
|
setmetatable(elist, eventListMeta)
|
||||||
e2d[elist] = dlist
|
e2d[elist] = dlist
|
||||||
e2s[elist] = sync
|
|
||||||
end
|
end
|
||||||
return dlist.elist
|
return dlist.elist
|
||||||
end
|
end
|
||||||
@ -954,8 +949,8 @@ local InletFactory = (function()
|
|||||||
-----
|
-----
|
||||||
-- Returns the sync from an event or list
|
-- Returns the sync from an event or list
|
||||||
--
|
--
|
||||||
local function getSync(agent)
|
local function getSync(event)
|
||||||
return e2s[agent]
|
return e2d[event].sync
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -1308,7 +1303,7 @@ local Sync = (function()
|
|||||||
alarm = now()
|
alarm = now()
|
||||||
end
|
end
|
||||||
-- new delay
|
-- new delay
|
||||||
local nd = Delay.new(etype, alarm, path, path2)
|
local nd = Delay.new(etype, self, alarm, path, path2)
|
||||||
if nd.etype == 'Init' or nd.etype == 'Blanket' then
|
if nd.etype == 'Init' or nd.etype == 'Blanket' then
|
||||||
-- always stack blanket events on the last event
|
-- always stack blanket events on the last event
|
||||||
log('Delay', 'Stacking ',nd.etype,' event.')
|
log('Delay', 'Stacking ',nd.etype,' event.')
|
||||||
@ -1385,7 +1380,7 @@ local Sync = (function()
|
|||||||
-- @param test function to test each delay
|
-- @param test function to test each delay
|
||||||
--
|
--
|
||||||
local function getDelays(self, test)
|
local function getDelays(self, test)
|
||||||
local dlist = {}
|
local dlist = { sync = self}
|
||||||
local dlistn = 1
|
local dlistn = 1
|
||||||
local blocks = {}
|
local blocks = {}
|
||||||
|
|
||||||
@ -1478,7 +1473,7 @@ local Sync = (function()
|
|||||||
-- Used as custom marker.
|
-- Used as custom marker.
|
||||||
--
|
--
|
||||||
local function addBlanketDelay(self)
|
local function addBlanketDelay(self)
|
||||||
local newd = Delay.new('Blanket', true, '')
|
local newd = Delay.new('Blanket', self, true, '')
|
||||||
newd.dpos = Queue.push(self.delays, newd)
|
newd.dpos = Queue.push(self.delays, newd)
|
||||||
return newd
|
return newd
|
||||||
end
|
end
|
||||||
@ -1488,7 +1483,7 @@ local Sync = (function()
|
|||||||
-- Used as startup marker to call init asap.
|
-- Used as startup marker to call init asap.
|
||||||
--
|
--
|
||||||
local function addInitDelay(self)
|
local function addInitDelay(self)
|
||||||
local newd = Delay.new('Init', true, '')
|
local newd = Delay.new('Init', self, true, '')
|
||||||
newd.dpos = Queue.push(self.delays, newd)
|
newd.dpos = Queue.push(self.delays, newd)
|
||||||
return newd
|
return newd
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user