0
这里的阵列迭代是一个数组我必须遍历到:通过散列
to_rsync = [{"src"=>"medical/",
"target"=>"212000/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"44/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"trisomie21/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"04/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"carrosse/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"49/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"53/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"72/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]},
{"src"=>"medical/",
"target"=>"85/App/",
"exclude"=>[".git", "nbproject", ".gitignore"]}]
我环绕在这样的:
lab_path = File.expand_path("~#{user}/lab")
webroot_path = File.expand_path("~#{user}/webroot")
Pry::ColorPrinter.pp(to_rsync)
to_rsync.each do |h|
src = File.join(lab_path, h["src"])
dst = File.join(webroot_path, h["target"])
sbx_sync src, dst, {:chown => 'www-data:www-data', :exclude => h["exclude"]}
end
我去槽的第一个元素,但我不不知道循环如何继续。
有人想知道为什么我不能遍历它吗?
编辑:问题已解决。 sbx_sync
停止执行。 这里是代码,以帮助您了解:
def sbx_sync(from, to, options = {})
# expand removes trailing slash
# cannot use str[-1] due to ruby 1.8.7 restriction
from = expand(from) + (from.end_with?('/') ? '/' : '')
to = expand(to) + (to.end_with?('/') ? '/' : '')
# default options
options = { :archive => true, :update => true }.merge(options)
ops = []
ops << '-a' if options[:archive]
ops << '-v' if options[:verbose]
ops << '-u' if options[:update]
ops << '-m' if options[:prune_empty]
ops << '-n' if @file_options[:noop]
Array(options[:exclude]).each do |path|
ops << "--exclude=#{ sh_escape(path) }"
end
ops << "--chown=#{ sh_escape(options[:chown]) }" if options[:chown]
ops << '--delete' if options[:delete]
command = "rsynC#{ ops.join(' ') } #{ sh_escape(from) } #{ sh_escape(to) } 2>&1"
puts command
#stdout = cmd(command)
#log("Sync from #{ sh_escape(from) } to #{ sh_escape(to) }. STDOUT:\n\n#{ stdout }")
end
的问题是在我评论了我的日志功能。
什么是'to_rsync'? – mudasobwa
'to_rsync'是一个像我之前展示的数组。 – sotaan