mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-07 10:50:51 +00:00
code beautification
This commit is contained in:
parent
27c211eaa4
commit
e869bbc1ca
41
fsevents.c
41
fsevents.c
|
@ -194,19 +194,17 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
|
||||||
switch(atype) {
|
switch(atype) {
|
||||||
case FSE_RENAME :
|
case FSE_RENAME :
|
||||||
if (path) {
|
if (path) {
|
||||||
/* for move events second string is target */
|
// for move events second string is target
|
||||||
trg = (char *) &arg->data.str;
|
trg = (char *) &arg->data.str;
|
||||||
}
|
}
|
||||||
/* fallthrough */
|
// fallthrough
|
||||||
case FSE_CHOWN :
|
case FSE_CHOWN :
|
||||||
case FSE_CONTENT_MODIFIED :
|
case FSE_CONTENT_MODIFIED :
|
||||||
case FSE_CREATE_FILE :
|
case FSE_CREATE_FILE :
|
||||||
case FSE_CREATE_DIR :
|
case FSE_CREATE_DIR :
|
||||||
case FSE_DELETE :
|
case FSE_DELETE :
|
||||||
case FSE_STAT_CHANGED :
|
case FSE_STAT_CHANGED :
|
||||||
if (!path) {
|
if (!path) path = (char *)&arg->data.str;
|
||||||
path = (char *)&arg->data.str;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -249,13 +247,11 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
|
||||||
|
|
||||||
if (etype) {
|
if (etype) {
|
||||||
if (!path) {
|
if (!path) {
|
||||||
printlogf(L, "Error",
|
printlogf(L, "Error", "Internal fail, fsevents, no path.");
|
||||||
"Internal fail, fsevents, no path.");
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
if (isdir < 0) {
|
if (isdir < 0) {
|
||||||
printlogf(L, "Error",
|
printlogf(L, "Error", "Internal fail, fsevents, neither dir nor file.");
|
||||||
"Internal fail, fsevents, neither dir nor file.");
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
load_runner_func(L, "fsEventsEvent");
|
load_runner_func(L, "fsEventsEvent");
|
||||||
|
@ -286,7 +282,7 @@ fsevents_ready(lua_State *L, struct observance *obs)
|
||||||
logstring("Error", "Internal, fsevents_fd != ob->fd");
|
logstring("Error", "Internal, fsevents_fd != ob->fd");
|
||||||
exit(-1); // ERRNO
|
exit(-1); // ERRNO
|
||||||
}
|
}
|
||||||
{
|
|
||||||
ptrdiff_t len = read (fsevents_fd, readbuf, readbuf_size);
|
ptrdiff_t len = read (fsevents_fd, readbuf, readbuf_size);
|
||||||
int err = errno;
|
int err = errno;
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
|
@ -354,7 +350,6 @@ fsevents_ready(lua_State *L, struct observance *obs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to close/tidy fsevents
|
* Called to close/tidy fsevents
|
||||||
|
@ -380,17 +375,17 @@ extern void
|
||||||
open_fsevents(lua_State *L)
|
open_fsevents(lua_State *L)
|
||||||
{
|
{
|
||||||
int8_t event_list[] = { // action to take for each event
|
int8_t event_list[] = { // action to take for each event
|
||||||
FSE_REPORT, /* FSE_CREATE_FILE */
|
FSE_REPORT, // FSE_CREATE_FILE
|
||||||
FSE_REPORT, /* FSE_DELETE */
|
FSE_REPORT, // FSE_DELETE
|
||||||
FSE_REPORT, /* FSE_STAT_CHANGED */
|
FSE_REPORT, // FSE_STAT_CHANGED
|
||||||
FSE_REPORT, /* FSE_RENAME */
|
FSE_REPORT, // FSE_RENAME
|
||||||
FSE_REPORT, /* FSE_CONTENT_MODIFIED */
|
FSE_REPORT, // FSE_CONTENT_MODIFIED
|
||||||
FSE_REPORT, /* FSE_EXCHANGE */
|
FSE_REPORT, // FSE_EXCHANGE
|
||||||
FSE_REPORT, /* FSE_FINDER_INFO_CHANGED */
|
FSE_REPORT, // FSE_FINDER_INFO_CHANGED
|
||||||
FSE_REPORT, /* FSE_CREATE_DIR */
|
FSE_REPORT, // FSE_CREATE_DIR
|
||||||
FSE_REPORT, /* FSE_CHOWN */
|
FSE_REPORT, // FSE_CHOWN
|
||||||
FSE_REPORT, /* FSE_XATTR_MODIFIED */
|
FSE_REPORT, // FSE_XATTR_MODIFIED
|
||||||
FSE_REPORT, /* FSE_XATTR_REMOVED */
|
FSE_REPORT, // FSE_XATTR_REMOVED
|
||||||
};
|
};
|
||||||
struct fsevent_clone_args fca = {
|
struct fsevent_clone_args fca = {
|
||||||
.event_list = (int8_t *) event_list,
|
.event_list = (int8_t *) event_list,
|
||||||
|
@ -428,7 +423,7 @@ open_fsevents(lua_State *L)
|
||||||
}
|
}
|
||||||
readbuf = s_malloc(readbuf_size);
|
readbuf = s_malloc(readbuf_size);
|
||||||
eventbuf = s_malloc(eventbuf_size);
|
eventbuf = s_malloc(eventbuf_size);
|
||||||
/* fd has been cloned, closes access fd */
|
// fd has been cloned, closes access fd
|
||||||
close(fd);
|
close(fd);
|
||||||
close_exec_fd(fsevents_fd);
|
close_exec_fd(fsevents_fd);
|
||||||
non_block_fd(fsevents_fd);
|
non_block_fd(fsevents_fd);
|
||||||
|
|
44
lsyncd.lua
44
lsyncd.lua
|
@ -686,10 +686,10 @@ local InletFactory = (function()
|
||||||
|
|
||||||
------
|
------
|
||||||
-- Returns the target.
|
-- Returns the target.
|
||||||
-- Just for user comfort, for most case
|
-- Just for user comfort
|
||||||
-- (Actually except of here, the lsyncd.runner itself
|
--
|
||||||
-- does not care event about the existance of "target",
|
-- (except here, the lsyncd.runner does not care event about the
|
||||||
-- this is completly up to the action scripts.)
|
-- existance of "target", this is up to the scripts.)
|
||||||
--
|
--
|
||||||
target = function(event)
|
target = function(event)
|
||||||
return e2s[event].config.target
|
return e2s[event].config.target
|
||||||
|
@ -1737,9 +1737,7 @@ local Syncs = (function()
|
||||||
-- the monitor to use
|
-- the monitor to use
|
||||||
config.monitor =
|
config.monitor =
|
||||||
settings.monitor or config.monitor or Monitors.default()
|
settings.monitor or config.monitor or Monitors.default()
|
||||||
if config.monitor ~= "inotify"
|
if config.monitor ~= "inotify" and config.monitor ~= "fsevents" then
|
||||||
and config.monitor ~= "fsevents"
|
|
||||||
then
|
|
||||||
local info = debug.getinfo(3, "Sl")
|
local info = debug.getinfo(3, "Sl")
|
||||||
log("Error", info.short_src, ":", info.currentline,
|
log("Error", info.short_src, ":", info.currentline,
|
||||||
": event monitor '",config.monitor,"' unknown.")
|
": event monitor '",config.monitor,"' unknown.")
|
||||||
|
@ -1796,11 +1794,11 @@ end)()
|
||||||
-- begins with root
|
-- begins with root
|
||||||
--
|
--
|
||||||
local function splitPath(path, root)
|
local function splitPath(path, root)
|
||||||
local rl = #root
|
local rlen = #root
|
||||||
local sp = string.sub(path, 1, rl)
|
local sp = string.sub(path, 1, rlen)
|
||||||
|
|
||||||
if sp == root then
|
if sp == root then
|
||||||
return string.sub(path, rl, -1)
|
return string.sub(path, rlen, -1)
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -2071,23 +2069,20 @@ local Fsevents = (function()
|
||||||
-----
|
-----
|
||||||
-- Called when any event has occured.
|
-- Called when any event has occured.
|
||||||
--
|
--
|
||||||
-- @param etype "Attrib", "Mofify", "Create", "Delete", "Move")
|
-- etype: 'Attrib', 'Mofify', 'Create', 'Delete', 'Move')
|
||||||
-- @param wd watch descriptor (matches lsyncd.inotifyadd())
|
-- isdir: true if filename is a directory
|
||||||
-- @param isdir true if filename is a directory
|
-- time: time of event
|
||||||
-- @param time time of event
|
-- path: path of file
|
||||||
-- @param filename string filename without path
|
-- path2: path of target in case of 'Move'
|
||||||
-- @param filename2
|
|
||||||
--
|
--
|
||||||
local function event(etype, isdir, time, path, path2)
|
local function event(etype, isdir, time, path, path2)
|
||||||
|
|
||||||
if isdir then
|
if isdir then
|
||||||
path = path..'/'
|
path = path..'/'
|
||||||
if path2 then
|
if path2 then path2 = path2..'/' end
|
||||||
path2 = path2 .. '/'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
log("Fsevents",etype,",",isdir,",",time,",",path,",",path2)
|
log('Fsevents',etype,',',isdir,',',time,',',path,',',path2)
|
||||||
|
|
||||||
for _, s in Syncs.iwalk() do repeat
|
for _, s in Syncs.iwalk() do repeat
|
||||||
local root = s.source
|
local root = s.source
|
||||||
|
@ -2100,18 +2095,16 @@ local Fsevents = (function()
|
||||||
relative2 = splitPath(path2, root)
|
relative2 = splitPath(path2, root)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- makes a copy of etype to possibly change it
|
-- possibly change etype for this iteration only
|
||||||
local etyped = etype
|
local etyped = etype
|
||||||
if etyped == 'Move' then
|
if etyped == 'Move' then
|
||||||
if not relative2 then
|
if not relative2 then
|
||||||
log("Normal", "Transformed Move to Create for ",
|
log('Normal', 'Transformed Move to Create for ', sync.config.name)
|
||||||
sync.config.name)
|
|
||||||
etyped = 'Create'
|
etyped = 'Create'
|
||||||
elseif not relative then
|
elseif not relative then
|
||||||
relative = relative2
|
relative = relative2
|
||||||
relative2 = nil
|
relative2 = nil
|
||||||
log("Normal", "Transformed Move to Delete for ",
|
log('Normal', 'Transformed Move to Delete for ', sync.config.name)
|
||||||
sync.config.name)
|
|
||||||
etyped = 'Delete'
|
etyped = 'Delete'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2344,6 +2337,7 @@ local functionWriter = (function()
|
||||||
else
|
else
|
||||||
ft = "function(event, event2)\n"
|
ft = "function(event, event2)\n"
|
||||||
end
|
end
|
||||||
|
-- TODO do array joining instead
|
||||||
ft = ft..' log("Normal", "Event " .. event.etype ..\n'
|
ft = ft..' log("Normal", "Event " .. event.etype ..\n'
|
||||||
ft = ft.." [[ spawns shell '"..lc..'\']])\n'
|
ft = ft.." [[ spawns shell '"..lc..'\']])\n'
|
||||||
ft = ft.." spawnShell(event, [["..cmd.. "]]"
|
ft = ft.." spawnShell(event, [["..cmd.. "]]"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user