mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-04 09:20:51 +00:00
user environments for user scripts
This commit is contained in:
parent
c98b865379
commit
517bbc157e
|
@ -46,6 +46,7 @@ set( LUA_CODE
|
|||
${PROJECT_SOURCE_DIR}/mantle/filter.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/lsyncd.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/wrapup.lua
|
||||
${PROJECT_SOURCE_DIR}/mantle/userenv.lua
|
||||
${PROJECT_SOURCE_DIR}/default/default.lua
|
||||
${PROJECT_SOURCE_DIR}/default/rsync.lua
|
||||
${PROJECT_SOURCE_DIR}/default/rsyncssh.lua
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
change: dropping exclude and excludeFrom (replaced by filter and filterFrom)
|
||||
change: "insist" by default
|
||||
change: removed _extra (if someone is hacky enough to really need it, they can hack Lsyncd itself)
|
||||
change: user scripts run in each of their own global lua environment
|
||||
|
||||
2018-03-09: 2.2.3
|
||||
enhaencement: supporting includes with new filter and filterFrom options
|
||||
|
|
34
core/core.c
34
core/core.c
|
@ -1614,17 +1614,17 @@ l_observe_fd( lua_State *L )
|
|||
|
||||
if( lua_isnil( L, -1 ) )
|
||||
{
|
||||
lua_pop ( L, 1 );
|
||||
lua_newtable ( L );
|
||||
lua_pushlightuserdata ( L, (void *) user_obs_ready );
|
||||
lua_pushvalue ( L, -2 );
|
||||
lua_settable ( L, LUA_REGISTRYINDEX );
|
||||
lua_pop( L, 1 );
|
||||
lua_newtable( L );
|
||||
lua_pushlightuserdata( L, (void *) user_obs_ready );
|
||||
lua_pushvalue( L, -2 );
|
||||
lua_settable( L, LUA_REGISTRYINDEX );
|
||||
}
|
||||
|
||||
lua_pushnumber ( L, fd );
|
||||
lua_pushvalue ( L, 2 );
|
||||
lua_settable ( L, -3 );
|
||||
lua_pop ( L, 1 );
|
||||
lua_pushnumber( L, fd );
|
||||
lua_pushvalue( L, 2 );
|
||||
lua_settable( L, -3 );
|
||||
lua_pop( L, 1 );
|
||||
|
||||
ready = true;
|
||||
}
|
||||
|
@ -2261,12 +2261,12 @@ main1( int argc, char *argv[] )
|
|||
exit( -1 );
|
||||
}
|
||||
|
||||
// asserts the Lsyncd's version matches
|
||||
// between mantle and core
|
||||
{
|
||||
// asserts the Lsyncd's version matches
|
||||
// double checks the if mantle version is the same as core version
|
||||
const char *lversion;
|
||||
|
||||
lua_getglobal( L, "mantle" );
|
||||
lua_getglobal( L, "lsyncd_version" );
|
||||
lversion = luaL_checkstring( L, -1 );
|
||||
|
||||
if( strcmp( lversion, PACKAGE_VERSION ) )
|
||||
|
@ -2276,13 +2276,13 @@ main1( int argc, char *argv[] )
|
|||
"Version mismatch luacode is '%s', but core is '%s'",
|
||||
lversion, PACKAGE_VERSION
|
||||
);
|
||||
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
lua_pop( L, 1 );
|
||||
}
|
||||
|
||||
|
||||
// checks if there is a "-help" or "--help"
|
||||
{
|
||||
int i;
|
||||
|
@ -2378,6 +2378,14 @@ main1( int argc, char *argv[] )
|
|||
exit( -1 );
|
||||
}
|
||||
|
||||
|
||||
// loads the user enivornment
|
||||
load_mci( L, "userENV" );
|
||||
if( lua_pcall( L, 0, 1, -2 ) ) exit( -1 );
|
||||
// removes the error handler from stack
|
||||
lua_remove( L, -2 );
|
||||
lua_setupvalue( L, -2, 1 );
|
||||
|
||||
if( lua_pcall( L, 0, LUA_MULTRET, 0) )
|
||||
{
|
||||
printlogf(
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -16,22 +16,13 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Safes mantle stuff
|
||||
--
|
||||
local core = core
|
||||
local log = core.log
|
||||
local Syncs
|
||||
local uSettings
|
||||
|
||||
|
||||
--
|
||||
-- Returns the relative part of absolute path if it
|
||||
-- begins with root
|
||||
|
@ -308,7 +299,4 @@ Inotify =
|
|||
addSync = addSync,
|
||||
event = event,
|
||||
statusReport = statusReport,
|
||||
|
||||
-- FIXME
|
||||
init = function( _Syncs, _uSettings ) Syncs = _Syncs; uSettings = _uSettings end
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
|
@ -1776,7 +1776,7 @@ function mci.callError
|
|||
(
|
||||
message
|
||||
)
|
||||
log( 'Error', 'in Lua: ', message )
|
||||
core.log( 'Error', 'in Lua: ', message )
|
||||
|
||||
-- prints backtrace
|
||||
local level = 2
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
|
74
mantle/userenv.lua
Normal file
74
mantle/userenv.lua
Normal file
|
@ -0,0 +1,74 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-- userenv.lua
|
||||
--
|
||||
--
|
||||
-- Setups up the global environment for a user script.
|
||||
--
|
||||
--
|
||||
-- License: GPLv2 (see COPYING) or any later version
|
||||
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||
--
|
||||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
mci.userENV =
|
||||
function
|
||||
( )
|
||||
local env =
|
||||
{
|
||||
-- generic lua stuff to be available
|
||||
_VERSION = _VERSION,
|
||||
assert = assert,
|
||||
bit32 = bit32,
|
||||
coroutine = coroutine,
|
||||
dofile = dofile,
|
||||
error = error,
|
||||
getmetatable = getmetable,
|
||||
io = io,
|
||||
ipairs = ipairs,
|
||||
load = load,
|
||||
loadfile = loadfile,
|
||||
loadstring = loadstring,
|
||||
math = math,
|
||||
module = module,
|
||||
next = next,
|
||||
os = os,
|
||||
package = package,
|
||||
pairs = pairs,
|
||||
pcall = pcall,
|
||||
print = print,
|
||||
rawequal = rawequal,
|
||||
rawlen = rawlen,
|
||||
rawget = rawget,
|
||||
rawset = rawset,
|
||||
require = require,
|
||||
select = select,
|
||||
setmetatable = setmetatable,
|
||||
string = string,
|
||||
table = table,
|
||||
type = type,
|
||||
unpack = unpack,
|
||||
|
||||
-- lsyncd mantle available to user scripts
|
||||
Array = Array,
|
||||
Queue = Queue,
|
||||
default = default,
|
||||
settings = settings,
|
||||
spawn = spawn,
|
||||
spawnShell = spawnShell,
|
||||
sync = sync,
|
||||
|
||||
-- lsyncd core available to user scripts
|
||||
log = log,
|
||||
nonobservefs = core.nonobserfd,
|
||||
now = core.now,
|
||||
observefd = core.observefd,
|
||||
readdir = core.readdir,
|
||||
terminate = core.terminate
|
||||
}
|
||||
|
||||
env._G = env
|
||||
|
||||
return env
|
||||
end
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
if mantle
|
||||
if lsyncd_version
|
||||
then
|
||||
print( 'Error, Lsyncd mantle already loaded' )
|
||||
os.exit( -1 )
|
||||
|
@ -21,15 +21,4 @@ end
|
|||
|
||||
|
||||
-- Lets the core double check version identity with the mantle
|
||||
mantle = '3.0.0-devel'
|
||||
|
||||
|
||||
Inotify.init( Syncs, uSettings )
|
||||
|
||||
|
||||
core = nil
|
||||
lockGlobals = nil
|
||||
Inotify = nil
|
||||
Delay = nil
|
||||
InletFactory = nil
|
||||
Filter = nil
|
||||
lsyncd_version = '3.0.0-devel'
|
||||
|
|
Loading…
Reference in New Issue
Block a user