diff options
author | Marius <mariausol@gmail.com> | 2013-10-20 01:21:09 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-10-20 01:21:09 +0300 |
commit | b8ac6d7b7fdb16293c28034c349efd5b0b7b20b3 (patch) | |
tree | 0e9051dbe21b4e9cfc72fe594df5b0fe7bc511f3 /scripts/context/lua/mtx-rsync.lua | |
parent | 965214d981e6129b782c67adcaf3a81aedcb0bac (diff) | |
download | context-b8ac6d7b7fdb16293c28034c349efd5b0b7b20b3.tar.gz |
beta 2013.10.20 07:09
Diffstat (limited to 'scripts/context/lua/mtx-rsync.lua')
-rw-r--r-- | scripts/context/lua/mtx-rsync.lua | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/scripts/context/lua/mtx-rsync.lua b/scripts/context/lua/mtx-rsync.lua index 65f795ee5..53cabbe4f 100644 --- a/scripts/context/lua/mtx-rsync.lua +++ b/scripts/context/lua/mtx-rsync.lua @@ -92,13 +92,26 @@ else end end -function rsynccommand(dryrun,recurse,origin,target) - local command = "rsync -ptlva " +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 type(exclude) == "table" then + for i=1,#exclude do + local e = exclude[i] + if e then + command = command .. ' --exclude "' .. e .. '"' + end + end + 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 @@ -109,7 +122,7 @@ local rsync = scripts.rsync rsync.mode = "command" -function rsync.run(origin,target,message,recurse) +function rsync.run(origin,target,message,recurse,delete,exclude) if type(origin) == "table" then origin = concat(origin,"/") end @@ -127,15 +140,15 @@ function rsync.run(origin,target,message,recurse) report_message(message) end if rsync.mode == "dryrun" then - local command = rsynccommand(true,recurse,origin,target) + local command = rsynccommand(origin,target,true,recurse,delete,exclude) report_dryrun(command.."\n") os.execute(command) elseif rsync.mode == "force" then - local command = rsynccommand(false,recurse,origin,target) + local command = rsynccommand(origin,target,false,recurse,delete,exclude) report_normal(command.."\n") os.execute(command) else - local command = rsynccommand(true,recurse,origin,target) + local command = rsynccommand(origin,target,true,recurse,delete,exclude) report_command(command) end end @@ -154,8 +167,10 @@ function rsync.job(list) local target = li.target 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) + rsync.run(origin,target,message,recurse,delete,exclude) else report_message("invalid job specification at index %s",i) end |