diff options
author | Marius <mariausol@gmail.com> | 2013-08-06 00:00:16 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-08-06 00:00:16 +0300 |
commit | 4bdbf185b1a7e0615f7eb8f3fe02bd13f46928c3 (patch) | |
tree | ae525f95a50ba76b9e97036f179f4be7584c76fa /scripts/context/lua/mtx-rsync.lua | |
parent | 3db68d82bb4eb24a3beb49bed1bf5c9799b3fcd5 (diff) | |
download | context-4bdbf185b1a7e0615f7eb8f3fe02bd13f46928c3.tar.gz |
beta 2013.08.05 22:51
Diffstat (limited to 'scripts/context/lua/mtx-rsync.lua')
-rw-r--r-- | scripts/context/lua/mtx-rsync.lua | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/scripts/context/lua/mtx-rsync.lua b/scripts/context/lua/mtx-rsync.lua index 70a82e929..53cabbe4f 100644 --- a/scripts/context/lua/mtx-rsync.lua +++ b/scripts/context/lua/mtx-rsync.lua @@ -92,19 +92,26 @@ else end end -function rsynccommand(origin,target,dryrun,recurse,delete) - local command = "rsync -t -p " +function rsynccommand(origin,target,dryrun,recurse,delete,exclude) + local command = "rsync -t -p" if dryrun then - command = command .. "-n " + command = command .. " -n" end if recurse then - command = command .. "-r " + command = command .. " -r" end - if delete then - if not recurse then - command = command .. "-d " + if type(exclude) == "table" then + for i=1,#exclude do + local e = exclude[i] + if e then + command = command .. ' --exclude "' .. e .. '"' + end end - command = command .. "--delete " + elseif type(exclude) == "string" then + command = command .. " --exclude-from " .. exclude + end + if delete and recurse then + command = command .. " --delete" end return format('%s %s %s',command,origin,target) end @@ -115,7 +122,7 @@ local rsync = scripts.rsync rsync.mode = "command" -function rsync.run(origin,target,message,recurse,delete) +function rsync.run(origin,target,message,recurse,delete,exclude) if type(origin) == "table" then origin = concat(origin,"/") end @@ -133,15 +140,15 @@ function rsync.run(origin,target,message,recurse,delete) report_message(message) end if rsync.mode == "dryrun" then - local command = rsynccommand(origin,target,true,recurse,delete) + local command = rsynccommand(origin,target,true,recurse,delete,exclude) report_dryrun(command.."\n") os.execute(command) elseif rsync.mode == "force" then - local command = rsynccommand(origin,target,false,recurse,delete) + local command = rsynccommand(origin,target,false,recurse,delete,exclude) report_normal(command.."\n") os.execute(command) else - local command = rsynccommand(origin,target,true,recurse,delete) + local command = rsynccommand(origin,target,true,recurse,delete,exclude) report_command(command) end end @@ -161,8 +168,9 @@ function rsync.job(list) local message = li.message local recurse = li.recurse local delete = li.delete + local exclude = li.exclude if origin and #origin > 0 and target and #target > 0 then -- string or table - rsync.run(origin,target,message,recurse,delete) + rsync.run(origin,target,message,recurse,delete,exclude) else report_message("invalid job specification at index %s",i) end |