2016-08-16 22:08:57 +00:00
|
|
|
require "shellwords"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module SyncedFolderRSync
|
|
|
|
# This module provides default rsync capabilities for
|
|
|
|
# unix type operating systems.
|
|
|
|
module DefaultUnixCap
|
|
|
|
|
|
|
|
def rsync_installed(machine)
|
|
|
|
machine.communicate.test("which rsync")
|
|
|
|
end
|
|
|
|
|
|
|
|
def rsync_command(machine)
|
|
|
|
"sudo rsync"
|
|
|
|
end
|
|
|
|
|
|
|
|
def rsync_pre(machine, opts)
|
|
|
|
guest_path = Shellwords.escape(opts[:guestpath])
|
|
|
|
machine.communicate.sudo("mkdir -p #{guest_path}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def rsync_post(machine, opts)
|
|
|
|
if opts.key?(:chown) && !opts[:chown]
|
|
|
|
return
|
|
|
|
end
|
2018-12-14 16:42:58 +00:00
|
|
|
|
2018-12-15 01:03:42 +00:00
|
|
|
machine.communicate.sudo(build_rsync_chown(opts))
|
2016-08-16 22:08:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_rsync_chown(opts)
|
|
|
|
guest_path = Shellwords.escape(opts[:guestpath])
|
2019-06-10 20:29:18 +00:00
|
|
|
if(opts[:exclude] && !Array(opts[:exclude]).empty?)
|
2016-08-16 22:08:57 +00:00
|
|
|
exclude_base = Pathname.new(opts[:guestpath])
|
|
|
|
exclusions = Array(opts[:exclude]).map do |ex_path|
|
|
|
|
ex_path = ex_path.slice(1, ex_path.size) if ex_path.start_with?(File::SEPARATOR)
|
2016-10-25 16:27:21 +00:00
|
|
|
"-path #{Shellwords.escape(exclude_base.join(ex_path))} -prune"
|
2016-08-16 22:08:57 +00:00
|
|
|
end.join(" -o ") + " -o "
|
|
|
|
end
|
|
|
|
"find #{guest_path} #{exclusions}" \
|
|
|
|
"'!' -type l -a " \
|
|
|
|
"'(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -exec " \
|
2018-12-14 16:42:58 +00:00
|
|
|
"chown #{opts[:owner]}:#{opts[:group]} '{}' +"
|
2016-08-16 22:08:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|