From d7af9882f4d690ff6324f7ec3527eb0e5bcb2a35 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 29 May 2010 23:33:37 -0700 Subject: [PATCH] Allow SSH commands to ignore exit status --- lib/vagrant/ssh.rb | 6 +++++- lib/vagrant/systems/linux.rb | 2 +- test/vagrant/systems/linux_test.rb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 047a48d2a..45d47b2a6 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -149,8 +149,12 @@ module Vagrant # the actual `exec!` implementation, except that this # implementation also reports `:exit_status` to the block if given. def exec!(command, options=nil, &block) + options = { + :error_check => true + }.merge(options || {}) + block ||= Proc.new do |ch, type, data| - check_exit_status(data, command, options) if type == :exit_status + check_exit_status(data, command, options) if type == :exit_status && options[:error_check] ch[:result] ||= "" ch[:result] << data if [:stdout, :stderr].include?(type) diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 055ae6e19..17e10286c 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -66,7 +66,7 @@ module Vagrant logger.info "Preparing system for rsync..." vm.ssh.upload!(StringIO.new(render_rsync), config.vm.rsync_script) ssh.exec!("sudo chmod +x #{config.vm.rsync_script}") - ssh.exec!("sudo rm #{config.vm.rsync_crontab_entry_file}") + ssh.exec!("sudo rm #{config.vm.rsync_crontab_entry_file}", :error_check => false) end #------------------------------------------------------------------- diff --git a/test/vagrant/systems/linux_test.rb b/test/vagrant/systems/linux_test.rb index 239a03722..fabc7c834 100644 --- a/test/vagrant/systems/linux_test.rb +++ b/test/vagrant/systems/linux_test.rb @@ -59,7 +59,7 @@ class LinuxSystemTest < Test::Unit::TestCase end should "remove old crontab entries file" do - @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.rsync_crontab_entry_file}") + @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.rsync_crontab_entry_file}", :error_check => false) @instance.prepare_rsync(@ssh) end