mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-05 16:12:32 +00:00
This commit is contained in:
parent
eadbb6a202
commit
0a6fac9c0c
65
lsyncd.lua
65
lsyncd.lua
@ -232,13 +232,12 @@ local Inlet, InletControl = (function()
|
|||||||
-- lua runner controlled variables
|
-- lua runner controlled variables
|
||||||
local sync
|
local sync
|
||||||
|
|
||||||
-- key variables for delays hidden from user
|
|
||||||
local delayKey = {}
|
|
||||||
|
|
||||||
-- nil for non move events
|
-----
|
||||||
-- 0 for move source events
|
-- table to receive the delay of a event.
|
||||||
-- 1 for move desination events
|
local e2d = {}
|
||||||
local moveDestKey = {}
|
-- doesnt stop the garbage collect to remove either.
|
||||||
|
setmetatable(e2d, { __mode = 'kv' })
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- removes the trailing slash from a path
|
-- removes the trailing slash from a path
|
||||||
@ -251,10 +250,10 @@ local Inlet, InletControl = (function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getPath(event)
|
local function getPath(event)
|
||||||
if not event[moveDestKey] then
|
if not event.move then
|
||||||
return event[delayKey].path
|
return e2d[event].path
|
||||||
else
|
else
|
||||||
return event[delayKey].path2
|
return e2d[event].path2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -269,7 +268,7 @@ local Inlet, InletControl = (function()
|
|||||||
-- TODO give user a readonly version.
|
-- TODO give user a readonly version.
|
||||||
--
|
--
|
||||||
config = function(event)
|
config = function(event)
|
||||||
return event[delayKey].sync.config
|
return e2d[event].sync.config
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -282,13 +281,13 @@ local Inlet, InletControl = (function()
|
|||||||
-- "Move"
|
-- "Move"
|
||||||
--
|
--
|
||||||
etype = function(event)
|
etype = function(event)
|
||||||
return event[delayKey].etype
|
return e2d[event].etype
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Status
|
-- Status
|
||||||
status = function(event)
|
status = function(event)
|
||||||
return event[delayKey].status
|
return e2d[event].status
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -389,7 +388,7 @@ local Inlet, InletControl = (function()
|
|||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
local f = eventFields[k]
|
local f = eventFields[k]
|
||||||
if not f then
|
if not f then
|
||||||
if k == moveDestKey then
|
if k == 'move' then
|
||||||
-- possibly undefined
|
-- possibly undefined
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -400,33 +399,35 @@ local Inlet, InletControl = (function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Encapsulates a delay to an event for the user
|
-- Encapsulates a delay into an event for the user
|
||||||
--
|
|
||||||
-- TODO this hidden key technique can be circumvented with
|
|
||||||
-- pairs(), use a weak table as referencer instead.
|
|
||||||
--
|
--
|
||||||
local function toEvent(delay)
|
local function toEvent(delay)
|
||||||
if delay.etype ~= "Move" then
|
if delay.etype ~= "Move" then
|
||||||
if not delay.event then
|
if not delay.event then
|
||||||
delay.event = {}
|
local event = {}
|
||||||
setmetatable(delay.event, eventMeta)
|
delay.event = event
|
||||||
delay.event[delayKey] = delay
|
setmetatable(event, eventMeta)
|
||||||
|
e2d[event] = delay
|
||||||
end
|
end
|
||||||
return delay.event
|
return delay.event
|
||||||
else
|
else
|
||||||
-- moves have 2 events - origin and destination
|
-- moves have 2 events - origin and destination
|
||||||
if not delay.event then
|
if not delay.event then
|
||||||
delay.event = {}
|
local event = {}
|
||||||
delay.event2 = {}
|
local event2 = {}
|
||||||
|
delay.event = event
|
||||||
|
delay.event2 = event2
|
||||||
|
|
||||||
setmetatable(delay.event, eventMeta)
|
setmetatable(event, eventMeta)
|
||||||
setmetatable(delay.event2, eventMeta)
|
setmetatable(event2, eventMeta)
|
||||||
|
e2d[delay.event] = delay
|
||||||
delay.event[delayKey] = delay
|
e2d[delay.event2] = delay
|
||||||
delay.event2[delayKey] = delay
|
|
||||||
|
-- move events have a field 'event'
|
||||||
delay.event[moveDestKey] = false
|
-- false for move source events
|
||||||
delay.event2[moveDestKey] = true
|
-- true for move desination events
|
||||||
|
event.move = false
|
||||||
|
event2.move = true
|
||||||
end
|
end
|
||||||
return delay.event, delay.event2
|
return delay.event, delay.event2
|
||||||
end
|
end
|
||||||
@ -445,7 +446,7 @@ local Inlet, InletControl = (function()
|
|||||||
-- Cancels a waiting event.
|
-- Cancels a waiting event.
|
||||||
--
|
--
|
||||||
local function cancelEvent(event)
|
local function cancelEvent(event)
|
||||||
local delay = event[delayKey]
|
local delay = e2d[event]
|
||||||
if delay.status ~= "wait" then
|
if delay.status ~= "wait" then
|
||||||
log("Error", "Ignored try to cancel a non-waiting event of type ",
|
log("Error", "Ignored try to cancel a non-waiting event of type ",
|
||||||
event.etype)
|
event.etype)
|
||||||
@ -481,7 +482,7 @@ local Inlet, InletControl = (function()
|
|||||||
-- Return the inner config
|
-- Return the inner config
|
||||||
-- not to be called from user
|
-- not to be called from user
|
||||||
local function getInterior(event)
|
local function getInterior(event)
|
||||||
return sync, event[delayKey]
|
return sync, e2d[event]
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
Loading…
Reference in New Issue
Block a user