From 06562964636b0adc626dc85b780af2909092f077 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Mon, 29 Nov 2010 16:37:46 +0000 Subject: [PATCH] fixing lbash --- examples/lbash.lua | 4 ++-- lsyncd.lua | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/examples/lbash.lua b/examples/lbash.lua index 1f17ff7..a7cdc31 100644 --- a/examples/lbash.lua +++ b/examples/lbash.lua @@ -29,9 +29,9 @@ bash = { onStartup = [[if [ "$(ls -A ^source)" ]; then cp -r ^source* ^target; fi]], - onCreate = prefix..[[cp -r ^sourcePath ^targetPath]], + onCreate = prefix..[[cp -r ^sourcePath ^targetPathdir]], - onModify = prefix..[[cp -r ^sourcePath ^targetPath]], + onModify = prefix..[[cp -r ^sourcePath ^targetPathdir]], onDelete = prefix..[[rm -rf ^targetPath]], diff --git a/lsyncd.lua b/lsyncd.lua index 169c214..9edb282 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -561,6 +561,15 @@ local Inlet, InletControl = (function() return sync.source .. getPath(event) end, + ------ + -- Returns the absolute dir of the file/dir. + -- Includes a trailing slash. + -- + sourcePathdir = function(event) + return sync.source .. + (string.match(getPath(event), "^(.*/)[^/]+/?") or "") + end, + ------ -- Returns the absolute path of the file/dir. -- Excludes a trailing slash for dirs. @@ -579,6 +588,7 @@ local Inlet, InletControl = (function() target = function(event) return sync.config.target end, + ------ -- Returns the relative dir/file appended to the target. @@ -588,6 +598,15 @@ local Inlet, InletControl = (function() return sync.config.target .. getPath(event) end, + ------ + -- Returns the dir of the dir/file appended to the target. + -- Includes a trailing slash. + -- + targetPathdir = function(event) + return sync.config.target .. + (string.match(getPath(event), "^(.*/)[^/]+/?") or "") + end, + ------ -- Returns the relative dir/file appended to the target. -- Excludes a trailing slash for dirs. @@ -1959,22 +1978,28 @@ local functionWriter = (function() { "%^pathdir", "event.pathdir" , 1, }, { "%^path", "event.path" , 1, }, { "%^sourcePathname", "event.sourcePathname" , 1, }, + { "%^sourcePathdir", "event.sourcePathdir" , 1, }, { "%^sourcePath", "event.sourcePath" , 1, }, { "%^source", "event.source" , 1, }, { "%^targetPathname", "event.targetPathname" , 1, }, + { "%^targetPathdir", "event.targetPathdir" , 1, }, { "%^targetPath", "event.targetPath" , 1, }, { "%^target", "event.target" , 1, }, { "%^o%.pathname", "event.pathname" , 1, }, { "%^o%.path", "event.path" , 1, }, { "%^o%.sourcePathname", "event.sourcePathname" , 1, }, + { "%^o%.sourcePathdir", "event.sourcePathdir" , 1, }, { "%^o%.sourcePath", "event.sourcePath" , 1, }, { "%^o%.targetPathname", "event.targetPathname" , 1, }, + { "%^o%.targetPathdir", "event.targetPathdir" , 1, }, { "%^o%.targetPath", "event.targetPath" , 1, }, { "%^d%.pathname", "event2.pathname" , 2, }, { "%^d%.path", "event2.path" , 2, }, { "%^d%.sourcePathname", "event2.sourcePathname" , 2, }, + { "%^d%.sourcePathdir", "event2.sourcePathdir" , 2, }, { "%^d%.sourcePath", "event2.sourcePath" , 2, }, { "%^d%.targetPathname", "event2.targetPathname" , 2, }, + { "%^d%.targetPathdir", "event2.targetPathdir" , 2, }, { "%^d%.targetPath", "event2.targetPath" , 2, }, }