mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 14:43:09 +00:00
This commit is contained in:
parent
9246cecb87
commit
9156f4c4c7
7
lsyncd.c
7
lsyncd.c
@ -739,7 +739,7 @@ l_exec(lua_State *L)
|
|||||||
/* start filling the pipe */
|
/* start filling the pipe */
|
||||||
len = write(pipefd[1], pipe_text, tlen);
|
len = write(pipefd[1], pipe_text, tlen);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
logstring("Normal", "broken pipe.");
|
logstring("Normal", "immediatly broken pipe.");
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
}
|
}
|
||||||
if (len == tlen) {
|
if (len == tlen) {
|
||||||
@ -747,8 +747,8 @@ l_exec(lua_State *L)
|
|||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
logstring("Exec", "one-sweeped pipe");
|
logstring("Exec", "one-sweeped pipe");
|
||||||
} else {
|
} else {
|
||||||
logstring("Exec", "adding delayed pipe");
|
|
||||||
int p = pipes_len;
|
int p = pipes_len;
|
||||||
|
logstring("Exec", "adding delayed pipe");
|
||||||
pipes_len++;
|
pipes_len++;
|
||||||
if (pipes_len > pipes_size) {
|
if (pipes_len > pipes_size) {
|
||||||
pipes_size = pipes_len;
|
pipes_size = pipes_len;
|
||||||
@ -756,6 +756,7 @@ l_exec(lua_State *L)
|
|||||||
}
|
}
|
||||||
pipes[p].fd = pipefd[1];
|
pipes[p].fd = pipefd[1];
|
||||||
pipes[p].tlen = tlen;
|
pipes[p].tlen = tlen;
|
||||||
|
pipes[p].pos = len;
|
||||||
pipes[p].text = s_strdup(pipe_text);
|
pipes[p].text = s_strdup(pipe_text);
|
||||||
}
|
}
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
@ -1223,7 +1224,7 @@ masterloop(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* reuse pi for result */
|
/* reuse pi for result */
|
||||||
pi = pselect(nfds + 1, &rfds, NULL, NULL,
|
pi = pselect(nfds + 1, &rfds, &wfds, NULL,
|
||||||
have_alarm ? &tv : NULL, &sigset);
|
have_alarm ? &tv : NULL, &sigset);
|
||||||
if (pi >= 0) {
|
if (pi >= 0) {
|
||||||
do_read = FD_ISSET(inotify_fd, &rfds);
|
do_read = FD_ISSET(inotify_fd, &rfds);
|
||||||
|
74
lsyncd.lua
74
lsyncd.lua
@ -425,9 +425,9 @@ local Inlet, InletControl = (function()
|
|||||||
--
|
--
|
||||||
local eventListFuncs = {
|
local eventListFuncs = {
|
||||||
-----
|
-----
|
||||||
-- Returns the pathnames of all events.
|
-- Returns the paths of all events.
|
||||||
--
|
--
|
||||||
getPathnames = function(elist, delimiter)
|
getPaths = function(elist, delimiter)
|
||||||
local dlist = el2dl[elist]
|
local dlist = el2dl[elist]
|
||||||
if not dlist then
|
if not dlist then
|
||||||
error("cannot find delay list from event list.")
|
error("cannot find delay list from event list.")
|
||||||
@ -449,6 +449,32 @@ local Inlet, InletControl = (function()
|
|||||||
end
|
end
|
||||||
return table.concat(pl, delimiter) .. delimiter
|
return table.concat(pl, delimiter) .. delimiter
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Returns the absolute local paths of all events.
|
||||||
|
--
|
||||||
|
getSourcePaths = function(elist, delimiter)
|
||||||
|
local dlist = el2dl[elist]
|
||||||
|
if not dlist then
|
||||||
|
error("cannot find delay list from event list.")
|
||||||
|
end
|
||||||
|
if not delimiter then
|
||||||
|
delimiter = '\n'
|
||||||
|
end
|
||||||
|
local pl = {}
|
||||||
|
local i = 1
|
||||||
|
for k, d in pairs(dlist) do
|
||||||
|
if type(k) == "number" then
|
||||||
|
pl[i] = sync.source .. d.path
|
||||||
|
i = i + 1
|
||||||
|
if d.path2 then
|
||||||
|
pl[i] = sync.source .. d.path2
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(pl, delimiter) .. delimiter
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -623,6 +649,7 @@ local Sync = (function()
|
|||||||
|
|
||||||
-----
|
-----
|
||||||
-- Removes a delay.
|
-- Removes a delay.
|
||||||
|
--
|
||||||
local function removeDelay(self, delay)
|
local function removeDelay(self, delay)
|
||||||
local found
|
local found
|
||||||
for i, d in ipairs(self.delays) do
|
for i, d in ipairs(self.delays) do
|
||||||
@ -640,9 +667,6 @@ local Sync = (function()
|
|||||||
-- free all delays blocked by this one.
|
-- free all delays blocked by this one.
|
||||||
if delay.blocks then
|
if delay.blocks then
|
||||||
for i, vd in pairs(delay.blocks) do
|
for i, vd in pairs(delay.blocks) do
|
||||||
if vd.status ~= "block" then
|
|
||||||
error("unblocking an non-blocked event!")
|
|
||||||
end
|
|
||||||
vd.status = "wait"
|
vd.status = "wait"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -733,6 +757,7 @@ local Sync = (function()
|
|||||||
if #self.delays > 0 then
|
if #self.delays > 0 then
|
||||||
stack(self.delays[#self.delays], nd)
|
stack(self.delays[#self.delays], nd)
|
||||||
end
|
end
|
||||||
|
addDelayPath("", nd)
|
||||||
table.insert(self.delays, nd)
|
table.insert(self.delays, nd)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -1676,17 +1701,48 @@ end
|
|||||||
--
|
--
|
||||||
local defaultRsync = {
|
local defaultRsync = {
|
||||||
-----
|
-----
|
||||||
-- Called for every sync/target pair on startup
|
-- Spawns rsync for a list of events
|
||||||
--
|
--
|
||||||
action = function(inlet)
|
action = function(inlet)
|
||||||
local elist = inlet.getEvents()
|
local elist = inlet.getEvents()
|
||||||
local pathnames = elist.getPathnames()
|
local config = inlet.getConfig()
|
||||||
log("Normal", "rsyncing list\n", pathnames)
|
local spaths = elist.getSourcePaths()
|
||||||
return spawn(elist, "/tmp/input", "<", pathnames)
|
log("Normal", "rsyncing list\n", spaths)
|
||||||
|
spawn(elist, "/usr/bin/rsync",
|
||||||
|
"<", spaths,
|
||||||
|
"--delete",
|
||||||
|
config.rsyncOps.."d",
|
||||||
|
"--include-from=-",
|
||||||
|
"--exclude=\"*\"",
|
||||||
|
config.source, config.target)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Spawns the recursive startup sync
|
||||||
|
--
|
||||||
|
init = function(inlet)
|
||||||
|
local config = inlet.getConfig()
|
||||||
|
local event = inlet.createBlanketEvent()
|
||||||
|
if string.sub(config.target, -1) ~= "/" then
|
||||||
|
config.target = config.target .. "/"
|
||||||
|
end
|
||||||
|
log("Normal", "recursive startup rsync: ", config.source,
|
||||||
|
" -> ", config.target)
|
||||||
|
spawn(event, "/usr/bin/rsync",
|
||||||
|
"--delete",
|
||||||
|
config.rsyncOps.."r",
|
||||||
|
config.source,
|
||||||
|
config.target)
|
||||||
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Calls rsync with this options
|
||||||
|
--
|
||||||
|
rsyncOps = "-lts",
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Default delay 3 seconds
|
-- Default delay 3 seconds
|
||||||
|
--
|
||||||
delay = 3,
|
delay = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user