Merge pull request #3544 from benesch/rsync-conservative-chown
synced_folders/rsync: only chown when necessary
This commit is contained in:
commit
ac040102f9
|
@ -6,13 +6,14 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"sudo rsync"
|
||||||
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
machine.communicate.sudo(
|
||||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
end
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("darwin", "rsync_pre") do
|
guest_capability("darwin", "rsync_command") do
|
||||||
|
require_relative "cap/rsync"
|
||||||
|
Cap::RSync
|
||||||
|
end
|
||||||
|
|
||||||
|
guest_capability("darwin", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,13 +12,14 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"sudo rsync"
|
||||||
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'", shell: "sh")
|
machine.communicate.sudo(
|
||||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'", shell: "sh")
|
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
end
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,7 +46,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("freebsd", "rsync_pre") do
|
guest_capability("freebsd", "rsync_command") do
|
||||||
|
require_relative "cap/rsync"
|
||||||
|
Cap::RSync
|
||||||
|
end
|
||||||
|
|
||||||
|
guest_capability("freebsd", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,23 +6,16 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"sudo rsync"
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
|
||||||
comm.sudo("mkdir -p '#{opts[:guestpath]}'")
|
|
||||||
comm.sudo("find '#{opts[:guestpath]}' ! -user #{username} -print0 | " +
|
|
||||||
"xargs -0 -r chown -v #{username}:")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_post(machine, opts)
|
def self.rsync_post(machine, opts)
|
||||||
machine.communicate.tap do |comm|
|
machine.communicate.sudo(
|
||||||
comm.sudo("find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -67,12 +67,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("linux", "rsync_post") do
|
guest_capability("linux", "rsync_command") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("linux", "rsync_pre") do
|
guest_capability("linux", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,13 +13,14 @@ module VagrantPlugins
|
||||||
'pkg_add rsync')
|
'pkg_add rsync')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"sudo rsync"
|
||||||
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
machine.communicate.sudo(
|
||||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
end
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,7 +46,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("netbsd", "rsync_pre") do
|
guest_capability("netbsd", "rsync_command") do
|
||||||
|
require_relative "cap/rsync"
|
||||||
|
Cap::RSync
|
||||||
|
end
|
||||||
|
|
||||||
|
guest_capability("netbsd", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,13 +13,14 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"sudo rsync"
|
||||||
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
machine.communicate.sudo(
|
||||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
end
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,7 +46,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("openbsd", "rsync_pre") do
|
guest_capability("openbsd", "rsync_command") do
|
||||||
|
require_relative "cap/rsync"
|
||||||
|
Cap::RSync
|
||||||
|
end
|
||||||
|
|
||||||
|
guest_capability("openbsd", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,14 +6,13 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"#{machine.config.smartos.suexec_cmd} rsync"
|
||||||
sudo = machine.config.smartos.suexec_cmd
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.execute("#{sudo} mkdir -p '#{folder_opts[:guestpath]}'")
|
machine.communicate.sudo("find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
comm.execute("#{sudo} chown -R #{username} '#{folder_opts[:guestpath]}'")
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("smartos", "rsync_pre") do
|
guest_capability("smartos", "rsync_command") do
|
||||||
|
require_relative "cap/rsync"
|
||||||
|
Cap::RSync
|
||||||
|
end
|
||||||
|
|
||||||
|
guest_capability("smartos", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,13 +6,15 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"#{machine.config.solaris.suexec_cmd} rsync"
|
||||||
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
su_cmd = machine.config.solaris.su_cmd
|
||||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
machine.communicate.execute(
|
||||||
end
|
"#{su_cmd} find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,12 @@ module VagrantPlugins
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
guest_capability("solaris", "rsync_pre") do
|
guest_capability("solaris", "rsync_command") do
|
||||||
|
require_relative "cap/rsync"
|
||||||
|
Cap::RSync
|
||||||
|
end
|
||||||
|
|
||||||
|
guest_capability("solaris", "rsync_post") do
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,13 +6,15 @@ module VagrantPlugins
|
||||||
machine.communicate.test("which rsync")
|
machine.communicate.test("which rsync")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_pre(machine, folder_opts)
|
def self.rsync_command(machine)
|
||||||
username = machine.ssh_info[:username]
|
"#{machine.config.solaris11.suexec_cmd} rsync"
|
||||||
|
end
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
def self.rsync_post(machine, opts)
|
||||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
su_cmd = machine.config.solaris11.su_cmd
|
||||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
machine.communicate.execute(
|
||||||
end
|
"#{su_cmd} '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
|
||||||
|
"xargs -0 -r chown -v #{opts[:owner]}:#{opts[:group]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,6 +90,17 @@ module VagrantPlugins
|
||||||
args << "--no-perms" if args.include?("--archive") || args.include?("-a")
|
args << "--no-perms" if args.include?("--archive") || args.include?("-a")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Disable rsync's owner/group preservation (implied by --archive) unless
|
||||||
|
# specifically requested, since we adjust owner/group to match shared
|
||||||
|
# folder setting ourselves.
|
||||||
|
args << "--no-owner" unless args.include?("--owner") || args.include?("-o")
|
||||||
|
args << "--no-group" unless args.include?("--group") || args.include?("-g")
|
||||||
|
|
||||||
|
# Tell local rsync how to invoke remote rsync with sudo
|
||||||
|
if machine.guest.capability?(:rsync_command)
|
||||||
|
args << "--rsync-path"<< machine.guest.capability(:rsync_command)
|
||||||
|
end
|
||||||
|
|
||||||
# Build up the actual command to execute
|
# Build up the actual command to execute
|
||||||
command = [
|
command = [
|
||||||
"rsync",
|
"rsync",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require File.expand_path("../../../../../base", __FILE__)
|
require File.expand_path("../../../../../base", __FILE__)
|
||||||
|
|
||||||
describe "VagrantPlugins::VagrantPlugins::Cap::Rsync" do
|
describe "VagrantPlugins::VagrantPlugins::Cap::Rsync" do
|
||||||
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:rsync_pre) }
|
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:rsync_installed) }
|
||||||
let(:machine) { double("machine") }
|
let(:machine) { double("machine") }
|
||||||
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
||||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||||
|
@ -30,23 +30,5 @@ describe "VagrantPlugins::VagrantPlugins::Cap::Rsync" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".rsync_pre" do
|
|
||||||
let(:username) { "some_user" }
|
|
||||||
|
|
||||||
before do
|
|
||||||
machine.stub(:ssh_info).and_return({username: username})
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates a local directory" do
|
|
||||||
communicator.expect_command(%Q(pfexec mkdir -p '/mountpoint'))
|
|
||||||
plugin.rsync_pre(machine, {guestpath: '/mountpoint'})
|
|
||||||
end
|
|
||||||
|
|
||||||
it "chowns local directory to ssh user" do
|
|
||||||
communicator.expect_command(%Q(pfexec chown -R #{username} '/mountpoint'))
|
|
||||||
plugin.rsync_pre(machine, {guestpath: '/mountpoint'})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue