code beautification

This commit is contained in:
Axel Kittenberger 2012-01-27 12:08:10 +01:00
parent 27c211eaa4
commit e869bbc1ca
3 changed files with 231 additions and 242 deletions

View File

@ -194,19 +194,17 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
switch(atype) {
case FSE_RENAME :
if (path) {
/* for move events second string is target */
// for move events second string is target
trg = (char *) &arg->data.str;
}
/* fallthrough */
// fallthrough
case FSE_CHOWN :
case FSE_CONTENT_MODIFIED :
case FSE_CREATE_FILE :
case FSE_CREATE_DIR :
case FSE_DELETE :
case FSE_STAT_CHANGED :
if (!path) {
path = (char *)&arg->data.str;
}
if (!path) path = (char *)&arg->data.str;
break;
}
break;
@ -249,13 +247,11 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
if (etype) {
if (!path) {
printlogf(L, "Error",
"Internal fail, fsevents, no path.");
printlogf(L, "Error", "Internal fail, fsevents, no path.");
exit(-1);
}
if (isdir < 0) {
printlogf(L, "Error",
"Internal fail, fsevents, neither dir nor file.");
printlogf(L, "Error", "Internal fail, fsevents, neither dir nor file.");
exit(-1);
}
load_runner_func(L, "fsEventsEvent");
@ -286,7 +282,7 @@ fsevents_ready(lua_State *L, struct observance *obs)
logstring("Error", "Internal, fsevents_fd != ob->fd");
exit(-1); // ERRNO
}
{
ptrdiff_t len = read (fsevents_fd, readbuf, readbuf_size);
int err = errno;
if (len == 0) {
@ -353,7 +349,6 @@ fsevents_ready(lua_State *L, struct observance *obs)
handle_event(L, event, len);
}
}
}
}
/**
@ -380,17 +375,17 @@ extern void
open_fsevents(lua_State *L)
{
int8_t event_list[] = { // action to take for each event
FSE_REPORT, /* FSE_CREATE_FILE */
FSE_REPORT, /* FSE_DELETE */
FSE_REPORT, /* FSE_STAT_CHANGED */
FSE_REPORT, /* FSE_RENAME */
FSE_REPORT, /* FSE_CONTENT_MODIFIED */
FSE_REPORT, /* FSE_EXCHANGE */
FSE_REPORT, /* FSE_FINDER_INFO_CHANGED */
FSE_REPORT, /* FSE_CREATE_DIR */
FSE_REPORT, /* FSE_CHOWN */
FSE_REPORT, /* FSE_XATTR_MODIFIED */
FSE_REPORT, /* FSE_XATTR_REMOVED */
FSE_REPORT, // FSE_CREATE_FILE
FSE_REPORT, // FSE_DELETE
FSE_REPORT, // FSE_STAT_CHANGED
FSE_REPORT, // FSE_RENAME
FSE_REPORT, // FSE_CONTENT_MODIFIED
FSE_REPORT, // FSE_EXCHANGE
FSE_REPORT, // FSE_FINDER_INFO_CHANGED
FSE_REPORT, // FSE_CREATE_DIR
FSE_REPORT, // FSE_CHOWN
FSE_REPORT, // FSE_XATTR_MODIFIED
FSE_REPORT, // FSE_XATTR_REMOVED
};
struct fsevent_clone_args fca = {
.event_list = (int8_t *) event_list,
@ -428,7 +423,7 @@ open_fsevents(lua_State *L)
}
readbuf = s_malloc(readbuf_size);
eventbuf = s_malloc(eventbuf_size);
/* fd has been cloned, closes access fd */
// fd has been cloned, closes access fd
close(fd);
close_exec_fd(fsevents_fd);
non_block_fd(fsevents_fd);

View File

@ -686,10 +686,10 @@ local InletFactory = (function()
------
-- Returns the target.
-- Just for user comfort, for most case
-- (Actually except of here, the lsyncd.runner itself
-- does not care event about the existance of "target",
-- this is completly up to the action scripts.)
-- Just for user comfort
--
-- (except here, the lsyncd.runner does not care event about the
-- existance of "target", this is up to the scripts.)
--
target = function(event)
return e2s[event].config.target
@ -1737,9 +1737,7 @@ local Syncs = (function()
-- the monitor to use
config.monitor =
settings.monitor or config.monitor or Monitors.default()
if config.monitor ~= "inotify"
and config.monitor ~= "fsevents"
then
if config.monitor ~= "inotify" and config.monitor ~= "fsevents" then
local info = debug.getinfo(3, "Sl")
log("Error", info.short_src, ":", info.currentline,
": event monitor '",config.monitor,"' unknown.")
@ -1796,11 +1794,11 @@ end)()
-- begins with root
--
local function splitPath(path, root)
local rl = #root
local sp = string.sub(path, 1, rl)
local rlen = #root
local sp = string.sub(path, 1, rlen)
if sp == root then
return string.sub(path, rl, -1)
return string.sub(path, rlen, -1)
else
return nil
end
@ -2071,23 +2069,20 @@ local Fsevents = (function()
-----
-- Called when any event has occured.
--
-- @param etype "Attrib", "Mofify", "Create", "Delete", "Move")
-- @param wd watch descriptor (matches lsyncd.inotifyadd())
-- @param isdir true if filename is a directory
-- @param time time of event
-- @param filename string filename without path
-- @param filename2
-- etype: 'Attrib', 'Mofify', 'Create', 'Delete', 'Move')
-- isdir: true if filename is a directory
-- time: time of event
-- path: path of file
-- path2: path of target in case of 'Move'
--
local function event(etype, isdir, time, path, path2)
if isdir then
path = path .. '/'
if path2 then
path2 = path2 .. '/'
end
path = path..'/'
if path2 then path2 = path2..'/' end
end
log("Fsevents",etype,",",isdir,",",time,",",path,",",path2)
log('Fsevents',etype,',',isdir,',',time,',',path,',',path2)
for _, s in Syncs.iwalk() do repeat
local root = s.source
@ -2100,18 +2095,16 @@ local Fsevents = (function()
relative2 = splitPath(path2, root)
end
-- makes a copy of etype to possibly change it
-- possibly change etype for this iteration only
local etyped = etype
if etyped == 'Move' then
if not relative2 then
log("Normal", "Transformed Move to Create for ",
sync.config.name)
log('Normal', 'Transformed Move to Create for ', sync.config.name)
etyped = 'Create'
elseif not relative then
relative = relative2
relative2 = nil
log("Normal", "Transformed Move to Delete for ",
sync.config.name)
log('Normal', 'Transformed Move to Delete for ', sync.config.name)
etyped = 'Delete'
end
end
@ -2344,11 +2337,12 @@ local functionWriter = (function()
else
ft = "function(event, event2)\n"
end
ft = ft .. ' log("Normal", "Event " .. event.etype ..\n'
ft = ft .. " [[ spawns shell '" .. lc .. '\']])\n'
ft = ft .. " spawnShell(event, [[" .. cmd .. "]]"
-- TODO do array joining instead
ft = ft..' log("Normal", "Event " .. event.etype ..\n'
ft = ft.." [[ spawns shell '"..lc..'\']])\n'
ft = ft.." spawnShell(event, [["..cmd.. "]]"
for _, v in ipairs(args) do
ft = ft .. ",\n " .. v
ft = ft..",\n "..v
end
ft = ft .. ")\nend"
return ft