From a6eafd6a127a752df3ffad6de3e7ee555581366c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 12 Mar 2014 18:43:59 -0700 Subject: [PATCH] synced_folders/rsync: execute rsync_post cap if it exists [GH-3163] --- CHANGELOG.md | 1 + plugins/guests/linux/cap/rsync.rb | 6 ++++++ plugins/guests/linux/plugin.rb | 5 +++++ plugins/synced_folders/rsync/helper.rb | 9 +++++++++ test/unit/plugins/synced_folders/rsync/helper_test.rb | 8 ++++++++ 5 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52fbd7572..9b461b279 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ BUG FIXES: retryable to avoid spurious VirtualBox errors. [GH-2831] - provisioners/ansible: Request SSH info within the provision method, when we know its available. [GH-3111] + - synced\_folders/rsync: owner/group settings work. [GH-3163] ## 1.5.0 (March 10, 2014) diff --git a/plugins/guests/linux/cap/rsync.rb b/plugins/guests/linux/cap/rsync.rb index 5469b3a13..46e6d48a4 100644 --- a/plugins/guests/linux/cap/rsync.rb +++ b/plugins/guests/linux/cap/rsync.rb @@ -14,6 +14,12 @@ module VagrantPlugins comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'") end end + + def self.rsync_post(machine, opts) + machine.communicate.tap do |comm| + comm.sudo("chown -R #{opts[:owner]}:#{opts[:group]} '#{opts[:guestpath]}'") + end + end end end end diff --git a/plugins/guests/linux/plugin.rb b/plugins/guests/linux/plugin.rb index 45c6e2bce..8aa903edd 100644 --- a/plugins/guests/linux/plugin.rb +++ b/plugins/guests/linux/plugin.rb @@ -61,6 +61,11 @@ module VagrantPlugins Cap::RSync end + guest_capability("linux", "rsync_post") do + require_relative "cap/rsync" + Cap::RSync + end + guest_capability("linux", "rsync_pre") do require_relative "cap/rsync" Cap::RSync diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index ab74a60a3..503f05e82 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -24,6 +24,10 @@ module VagrantPlugins hostpath += "/" end + # Folder options + opts[:owner] ||= ssh_info[:username] + opts[:group] ||= ssh_info[:username] + # Connection information username = ssh_info[:username] host = ssh_info[:host] @@ -77,6 +81,11 @@ module VagrantPlugins hostpath: hostpath, stderr: r.stderr end + + # If we have tasks to do after rsyncing, do those. + if machine.guest.capability?(:rsync_post) + machine.guest.capability(:rsync_post, opts) + end end end end diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 9e98b7539..b416b4902 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -122,6 +122,14 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do subject.rsync_single(machine, ssh_info, opts) end + it "executes the rsync_post capability after if it exists" do + guest.should_receive(:capability?).with(:rsync_post).and_return(true) + Vagrant::Util::Subprocess.should_receive(:execute).ordered.and_return(result) + guest.should_receive(:capability).with(:rsync_post, opts).ordered + + subject.rsync_single(machine, ssh_info, opts) + end + context "excluding files" do it "excludes files if given as a string" do opts[:exclude] = "foo"