From eec0986bc735889b9d7637316daf178b1ac67535 Mon Sep 17 00:00:00 2001 From: John Bender Date: Sat, 5 Jun 2010 00:39:25 -0700 Subject: [PATCH] switched directory syncing over to unison --- config/default.rb | 6 +- lib/vagrant/actions/vm/shared_folders.rb | 12 +- lib/vagrant/config.rb | 26 ++-- lib/vagrant/systems/linux.rb | 28 ++-- templates/crontab_entry.erb | 2 +- templates/{rsync.erb => sync.erb} | 6 +- test/test_helper.rb | 4 +- .../vagrant/actions/vm/shared_folders_test.rb | 20 +-- test/vagrant/config_test.rb | 30 ++-- test/vagrant/systems/linux_test.rb | 38 +++--- vagrant.gemspec | 128 +++++++++--------- 11 files changed, 150 insertions(+), 150 deletions(-) rename templates/{rsync.erb => sync.erb} (67%) diff --git a/config/default.rb b/config/default.rb index 46fd4eef6..eeea9739a 100644 --- a/config/default.rb +++ b/config/default.rb @@ -28,9 +28,9 @@ Vagrant::Config.run do |config| config.vm.share_folder("v-root", "/vagrant", ".") # TODO new config class - config.vm.rsync_opts = "-ur --delete" - config.vm.rsync_script = "/tmp/rsync" - config.vm.rsync_crontab_entry_file = "/tmp/crontab-entry" + config.vm.sync_opts = "-terse -group -owner -batch -silent" + config.vm.sync_script = "/tmp/sync" + config.vm.sync_crontab_entry_file = "/tmp/crontab-entry" config.package.name = 'vagrant' config.package.extension = '.box' diff --git a/lib/vagrant/actions/vm/shared_folders.rb b/lib/vagrant/actions/vm/shared_folders.rb index a10e6202a..07aa12ea5 100644 --- a/lib/vagrant/actions/vm/shared_folders.rb +++ b/lib/vagrant/actions/vm/shared_folders.rb @@ -5,7 +5,7 @@ module Vagrant def shared_folders @runner.env.config.vm.shared_folders.inject([]) do |acc, data| name, value = data - acc << [name, File.expand_path(value[:hostpath], @runner.env.root_path), value[:guestpath], value[:rsyncpath]].compact + acc << [name, File.expand_path(value[:hostpath], @runner.env.root_path), value[:guestpath], value[:syncpath]].compact end end @@ -18,13 +18,13 @@ module Vagrant logger.info "Mounting shared folders..." @runner.ssh.execute do |ssh| - @runner.system.prepare_rsync(ssh) if @runner.env.config.vm.rsync_required + @runner.system.prepare_sync(ssh) if @runner.env.config.vm.sync_required - shared_folders.each do |name, hostpath, guestpath, rsyncpath| - logger.info "-- #{name}: #{rsyncpath ? guestpath + " -rsync-> " + rsyncpath : guestpath}" + shared_folders.each do |name, hostpath, guestpath, syncpath| + logger.info "-- #{name}: #{syncpath ? guestpath + " -sync-> " + syncpath : guestpath}" @runner.system.mount_shared_folder(ssh, name, guestpath) - if rsyncpath - @runner.system.create_rsync(ssh, :rsyncpath => rsyncpath, :guestpath => guestpath) + if syncpath + @runner.system.create_sync(ssh, :syncpath => syncpath, :guestpath => guestpath) end end end diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index d2685f7b1..b6e724e39 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -85,10 +85,10 @@ module Vagrant attr_accessor :box_ovf attr_accessor :base_mac attr_accessor :boot_mode - attr_accessor :rsync_opts - attr_accessor :rsync_script - attr_accessor :rsync_crontab_entry_file - attr_reader :rsync_required + attr_accessor :sync_opts + attr_accessor :sync_script + attr_accessor :sync_crontab_entry_file + attr_reader :sync_required attr_reader :forwarded_ports attr_reader :shared_folders attr_reader :network_options @@ -129,15 +129,15 @@ module Vagrant end def share_folder(name, guestpath, hostpath = nil, opts = {}) - guestpath, opts[:rsync] = shift(guestpath, opts[:rsync]) + guestpath, opts[:sync] = shift(guestpath, opts[:sync]) # TODO if both are nil the exception information will be unusable - if opts[:rsync] == guestpath - raise Exception.new("The rsync directory #{opts[:rsync]} is identical to the shifted shared folder mount point #{guestpath}") + if opts[:sync] == guestpath + raise Exception.new("The sync directory #{opts[:sync]} is identical to the shifted shared folder mount point #{guestpath}") end @shared_folders[name] = { - :rsyncpath => opts[:rsync], + :syncpath => opts[:sync], :guestpath => guestpath, :hostpath => hostpath } @@ -186,12 +186,12 @@ module Vagrant defined_vms[name.to_sym].push_proc(&block) end - def shift(orig, rsync) - if rsync - @rsync_required = true - [orig + '-rsync', rsync == true ? orig : rsync] + def shift(orig, sync) + if sync + @sync_required = true + [orig + '-sync', sync == true ? orig : sync] else - [orig, rsync] + [orig, sync] end end end diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 267951023..170acc0d5 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -52,21 +52,21 @@ module Vagrant chown(ssh, guestpath) end - def create_rsync(ssh, opts) - crontab_entry = render_crontab_entry(opts.merge(:rsyncopts => config.vm.rsync_opts, - :scriptname => config.vm.rsync_script)) + def create_sync(ssh, opts) + crontab_entry = render_crontab_entry(opts.merge(:syncopts => config.vm.sync_opts, + :scriptname => config.vm.sync_script)) - ssh.exec!("sudo mkdir -p #{opts[:rsyncpath]}") - chown(ssh, opts[:rsyncpath]) - ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.rsync_crontab_entry_file}") - ssh.exec!("crontab #{config.vm.rsync_crontab_entry_file}") + ssh.exec!("sudo mkdir -p #{opts[:syncpath]}") + chown(ssh, opts[:syncpath]) + ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.sync_crontab_entry_file}") + ssh.exec!("crontab #{config.vm.sync_crontab_entry_file}") end - def prepare_rsync(ssh) - 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}", :error_check => false) + def prepare_sync(ssh) + logger.info "Preparing system for sync..." + vm.ssh.upload!(StringIO.new(render_sync), config.vm.sync_script) + ssh.exec!("sudo chmod +x #{config.vm.sync_script}") + ssh.exec!("sudo rm #{config.vm.sync_crontab_entry_file}", :error_check => false) end def prepare_host_only_network @@ -125,8 +125,8 @@ module Vagrant vm.env.config end - def render_rsync - TemplateRenderer.render('rsync') + def render_sync + TemplateRenderer.render('sync') end def render_crontab_entry(opts) diff --git a/templates/crontab_entry.erb b/templates/crontab_entry.erb index 11afa2e2b..6c075d58d 100644 --- a/templates/crontab_entry.erb +++ b/templates/crontab_entry.erb @@ -1 +1 @@ -* * * * * <%= scriptname %> '<%= rsyncopts %>' '<%= guestpath %>/' '<%= rsyncpath %>/' +* * * * * <%= scriptname %> '<%= syncopts %>' '<%= guestpath %>' '<%= syncpath %>' '-prefer <%= guestpath %>' diff --git a/templates/rsync.erb b/templates/sync.erb similarity index 67% rename from templates/rsync.erb rename to templates/sync.erb index 7b5109121..139eb2afc 100644 --- a/templates/rsync.erb +++ b/templates/sync.erb @@ -3,11 +3,11 @@ TIMESTART=`date +%s` while [ 1 ] do echo 'Syncing...' - rsync $1 $2 $3 - TIME=$((`date +%s`-$TIMESTART)) + unison $1 $2 $3 $4 + TIME=$((`date +%s`-$TIMESTART)) echo $TIME if [ $TIME -ge 50 ] - then + then break fi sleep 1 diff --git a/test/test_helper.rb b/test/test_helper.rb index 074ea8b3c..2d699f8b4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,8 +42,8 @@ class Test::Unit::TestCase config.vm.shared_folder_uid = nil config.vm.shared_folder_gid = nil config.vm.system = :linux - config.vm.rsync_script = "/foo" - config.vm.rsync_crontab_entry_file = "/tmp/foo" + config.vm.sync_script = "/foo" + config.vm.sync_crontab_entry_file = "/tmp/foo" config.vm.share_folder("v-root", "/vagrant", ".") config.package.name = 'vagrant' diff --git a/test/vagrant/actions/vm/shared_folders_test.rb b/test/vagrant/actions/vm/shared_folders_test.rb index c66520663..d4249e76b 100644 --- a/test/vagrant/actions/vm/shared_folders_test.rb +++ b/test/vagrant/actions/vm/shared_folders_test.rb @@ -47,11 +47,11 @@ class SharedFoldersActionTest < Test::Unit::TestCase assert_equal result, @action.shared_folders end - context "with rsync" do - should "append the rsync value to the other config values" do - mock_env_shared_folders(:rsync => true) + context "with sync" do + should "append the sync value to the other config values" do + mock_env_shared_folders(:sync => true) - assert_equal [["foo", "baz", "bar-rsync", "bar"]], @action.shared_folders + assert_equal [["foo", "baz", "bar-sync", "bar"]], @action.shared_folders end end @@ -123,10 +123,10 @@ class SharedFoldersActionTest < Test::Unit::TestCase @action.after_boot end - should "execute the necessary rysnc commands for each rsync folder" do - @folders.map { |f| f << 'rsync' } - @folders.each do |name, hostpath, guestpath, rsyncd| - @runner.system.expects(:create_rsync).with(@ssh, :rsyncpath => rsyncd, :guestpath => guestpath) + should "execute the necessary rysnc commands for each sync folder" do + @folders.map { |f| f << 'sync' } + @folders.each do |name, hostpath, guestpath, syncd| + @runner.system.expects(:create_sync).with(@ssh, :syncpath => syncd, :guestpath => guestpath) end @runner.ssh.expects(:execute).yields(@ssh) @@ -134,9 +134,9 @@ class SharedFoldersActionTest < Test::Unit::TestCase end end - context "with rsyncd folders" do + context "with syncd folders" do # TODO prevented by odd configuration swapping when stubbing ssh.execute - should "prepare the system for rsync if necessary" do + should "prepare the system for sync if necessary" do end end end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index 866cf3247..8bd0fda53 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -262,32 +262,32 @@ class ConfigTest < Test::Unit::TestCase end end - context "rsyncd folders" do - should "set the rsyncpath to nil by default" do + context "syncd folders" do + should "set the syncpath to nil by default" do share_with_opts - assert !@config.shared_folders['foo'][:rsyncpath] + assert !@config.shared_folders['foo'][:syncpath] end - should "append rsync to directory name when boolean" do - share_with_opts(:rsync => true) - assert_equal @config.shared_folders['foo'][:rsyncpath], 'foo-dir' - assert_equal @config.shared_folders['foo'][:guestpath], 'foo-dir-rsync' + should "append sync to directory name when boolean" do + share_with_opts(:sync => true) + assert_equal @config.shared_folders['foo'][:syncpath], 'foo-dir' + assert_equal @config.shared_folders['foo'][:guestpath], 'foo-dir-sync' end - should "use the specified rsync directory" do - share_with_opts(:rsync => 'bar-baz') - assert_equal @config.shared_folders['foo'][:rsyncpath], 'bar-baz' + should "use the specified sync directory" do + share_with_opts(:sync => 'bar-baz') + assert_equal @config.shared_folders['foo'][:syncpath], 'bar-baz' end - should "raise an exception an exception if the guestpath and rsyncpath are the same" do + should "raise an exception an exception if the guestpath and syncpath are the same" do assert_raise Exception do - share_with_opts(:rsync => 'foo-dir-rsync') + share_with_opts(:sync => 'foo-dir-sync') end end - should "set the rsync required flag to true" do - share_with_opts(:rsync => true) - assert @config.rsync_required + should "set the sync required flag to true" do + share_with_opts(:sync => true) + assert @config.sync_required end def share_with_opts(opts={}) diff --git a/test/vagrant/systems/linux_test.rb b/test/vagrant/systems/linux_test.rb index fabc7c834..a31b67909 100644 --- a/test/vagrant/systems/linux_test.rb +++ b/test/vagrant/systems/linux_test.rb @@ -43,59 +43,59 @@ class LinuxSystemTest < Test::Unit::TestCase end end - context "preparing rsync" do + context "preparing sync" do setup do @ssh.stubs(:exec!) @vm.stubs(:ssh).returns(@ssh) @vm.ssh.stubs(:upload!) end - should "upload the rsync template" do + should "upload the sync template" do @vm.ssh.expects(:upload!).with do |string_io, guest_path| - string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.rsync_script + string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.sync_script end - @instance.prepare_rsync(@ssh) + @instance.prepare_sync(@ssh) end should "remove old crontab entries file" do - @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.rsync_crontab_entry_file}", :error_check => false) - @instance.prepare_rsync(@ssh) + @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.sync_crontab_entry_file}", :error_check => false) + @instance.prepare_sync(@ssh) end - should "prepare the rsync template for execution" do - @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.rsync_script}") - @instance.prepare_rsync(@ssh) + should "prepare the sync template for execution" do + @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.sync_script}") + @instance.prepare_sync(@ssh) end end - context "setting up an rsync folder" do + context "setting up an sync folder" do setup do @ssh.stubs(:exec!) end should "create the new rysnc destination directory" do - rsync_path = 'foo' - @ssh.expects(:exec!).with("sudo mkdir -p #{rsync_path}") - @instance.create_rsync(@ssh, :rsyncpath => "foo") + sync_path = 'foo' + @ssh.expects(:exec!).with("sudo mkdir -p #{sync_path}") + @instance.create_sync(@ssh, :syncpath => "foo") end should "add an entry to the crontab file" do @instance.expects(:render_crontab_entry).returns('foo') @ssh.expects(:exec!).with do |cmd| - cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.rsync_crontab_entry_file}/ + cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.sync_crontab_entry_file}/ end - @instance.create_rsync(@ssh, {}) + @instance.create_sync(@ssh, {}) end should "use the crontab entry file to define vagrant users cron entries" do - @ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.rsync_crontab_entry_file}") - @instance.create_rsync(@ssh, {}) + @ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.sync_crontab_entry_file}") + @instance.create_sync(@ssh, {}) end - should "chown the rsync directory" do + should "chown the sync directory" do @instance.expects(:chown).with(@ssh, "foo") - @instance.create_rsync(@ssh, :rsyncpath => "foo") + @instance.create_sync(@ssh, :syncpath => "foo") end should "return provide a formatted crontab entry that runs every minute" do diff --git a/vagrant.gemspec b/vagrant.gemspec index 3044a3267..aaea08b74 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.authors = ["Mitchell Hashimoto", "John Bender"] - s.date = %q{2010-06-03} + s.date = %q{2010-06-05} s.default_executable = %q{vagrant} s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"] @@ -109,9 +109,9 @@ Gem::Specification.new do |s| "templates/crontab_entry.erb", "templates/network_entry.erb", "templates/package_Vagrantfile.erb", - "templates/rsync.erb", "templates/ssh_config.erb", "templates/strings.yml", + "templates/sync.erb", "test/test_helper.rb", "test/vagrant/actions/base_test.rb", "test/vagrant/actions/box/add_test.rb", @@ -189,75 +189,75 @@ Gem::Specification.new do |s| s.rubygems_version = %q{1.3.6} s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.test_files = [ - "test/test_helper.rb", - "test/vagrant/vm_test.rb", - "test/vagrant/command_test.rb", - "test/vagrant/environment_test.rb", - "test/vagrant/util_test.rb", + "test/vagrant/util_test.rb", "test/vagrant/box_test.rb", - "test/vagrant/busy_test.rb", - "test/vagrant/provisioners/base_test.rb", - "test/vagrant/provisioners/chef_test.rb", - "test/vagrant/provisioners/chef_server_test.rb", - "test/vagrant/provisioners/chef_solo_test.rb", - "test/vagrant/systems/linux_test.rb", - "test/vagrant/config_test.rb", - "test/vagrant/actions/base_test.rb", - "test/vagrant/actions/runner_test.rb", - "test/vagrant/actions/box/verify_test.rb", - "test/vagrant/actions/box/destroy_test.rb", - "test/vagrant/actions/box/add_test.rb", - "test/vagrant/actions/box/unpackage_test.rb", - "test/vagrant/actions/box/download_test.rb", - "test/vagrant/actions/collection_test.rb", - "test/vagrant/actions/vm/reload_test.rb", - "test/vagrant/actions/vm/suspend_test.rb", - "test/vagrant/actions/vm/boot_test.rb", - "test/vagrant/actions/vm/package_test.rb", - "test/vagrant/actions/vm/down_test.rb", - "test/vagrant/actions/vm/shared_folders_test.rb", - "test/vagrant/actions/vm/destroy_test.rb", - "test/vagrant/actions/vm/halt_test.rb", - "test/vagrant/actions/vm/import_test.rb", - "test/vagrant/actions/vm/customize_test.rb", - "test/vagrant/actions/vm/start_test.rb", - "test/vagrant/actions/vm/network_test.rb", - "test/vagrant/actions/vm/move_hard_drive_test.rb", - "test/vagrant/actions/vm/up_test.rb", - "test/vagrant/actions/vm/export_test.rb", - "test/vagrant/actions/vm/provision_test.rb", - "test/vagrant/actions/vm/resume_test.rb", - "test/vagrant/actions/vm/forward_ports_test.rb", - "test/vagrant/active_list_test.rb", - "test/vagrant/commands/base_test.rb", - "test/vagrant/commands/reload_test.rb", - "test/vagrant/commands/ssh_config_test.rb", - "test/vagrant/commands/suspend_test.rb", - "test/vagrant/commands/package_test.rb", - "test/vagrant/commands/status_test.rb", - "test/vagrant/commands/init_test.rb", - "test/vagrant/commands/destroy_test.rb", - "test/vagrant/commands/halt_test.rb", - "test/vagrant/commands/box/remove_test.rb", - "test/vagrant/commands/box/add_test.rb", - "test/vagrant/commands/box/list_test.rb", - "test/vagrant/commands/up_test.rb", - "test/vagrant/commands/provision_test.rb", - "test/vagrant/commands/resume_test.rb", - "test/vagrant/commands/ssh_test.rb", "test/vagrant/resource_logger_test.rb", + "test/vagrant/ssh_test.rb", + "test/vagrant/environment_test.rb", + "test/vagrant/provisioners/base_test.rb", + "test/vagrant/provisioners/chef_solo_test.rb", + "test/vagrant/provisioners/chef_server_test.rb", + "test/vagrant/provisioners/chef_test.rb", + "test/vagrant/commands/ssh_test.rb", + "test/vagrant/commands/destroy_test.rb", + "test/vagrant/commands/resume_test.rb", + "test/vagrant/commands/halt_test.rb", + "test/vagrant/commands/provision_test.rb", + "test/vagrant/commands/status_test.rb", + "test/vagrant/commands/base_test.rb", + "test/vagrant/commands/up_test.rb", + "test/vagrant/commands/reload_test.rb", + "test/vagrant/commands/package_test.rb", + "test/vagrant/commands/init_test.rb", + "test/vagrant/commands/ssh_config_test.rb", + "test/vagrant/commands/box/list_test.rb", + "test/vagrant/commands/box/add_test.rb", + "test/vagrant/commands/box/remove_test.rb", + "test/vagrant/commands/suspend_test.rb", + "test/vagrant/config_test.rb", + "test/vagrant/vm_test.rb", "test/vagrant/downloaders/base_test.rb", - "test/vagrant/downloaders/file_test.rb", "test/vagrant/downloaders/http_test.rb", - "test/vagrant/util/stacked_proc_runner_test.rb", + "test/vagrant/downloaders/file_test.rb", + "test/vagrant/command_test.rb", + "test/vagrant/active_list_test.rb", + "test/vagrant/busy_test.rb", + "test/vagrant/systems/linux_test.rb", + "test/vagrant/ssh_session_test.rb", "test/vagrant/util/output_helper_test.rb", + "test/vagrant/util/plain_logger_test.rb", + "test/vagrant/util/stacked_proc_runner_test.rb", + "test/vagrant/util/error_helper_test.rb", + "test/vagrant/util/platform_test.rb", "test/vagrant/util/template_renderer_test.rb", "test/vagrant/util/translator_test.rb", - "test/vagrant/util/platform_test.rb", - "test/vagrant/util/error_helper_test.rb", - "test/vagrant/util/plain_logger_test.rb", - "test/vagrant/ssh_session_test.rb", - "test/vagrant/ssh_test.rb" + "test/vagrant/actions/vm/start_test.rb", + "test/vagrant/actions/vm/destroy_test.rb", + "test/vagrant/actions/vm/customize_test.rb", + "test/vagrant/actions/vm/resume_test.rb", + "test/vagrant/actions/vm/halt_test.rb", + "test/vagrant/actions/vm/provision_test.rb", + "test/vagrant/actions/vm/import_test.rb", + "test/vagrant/actions/vm/network_test.rb", + "test/vagrant/actions/vm/up_test.rb", + "test/vagrant/actions/vm/boot_test.rb", + "test/vagrant/actions/vm/reload_test.rb", + "test/vagrant/actions/vm/shared_folders_test.rb", + "test/vagrant/actions/vm/package_test.rb", + "test/vagrant/actions/vm/move_hard_drive_test.rb", + "test/vagrant/actions/vm/forward_ports_test.rb", + "test/vagrant/actions/vm/suspend_test.rb", + "test/vagrant/actions/vm/down_test.rb", + "test/vagrant/actions/vm/export_test.rb", + "test/vagrant/actions/base_test.rb", + "test/vagrant/actions/runner_test.rb", + "test/vagrant/actions/collection_test.rb", + "test/vagrant/actions/box/destroy_test.rb", + "test/vagrant/actions/box/download_test.rb", + "test/vagrant/actions/box/verify_test.rb", + "test/vagrant/actions/box/unpackage_test.rb", + "test/vagrant/actions/box/add_test.rb", + "test/test_helper.rb" ] if s.respond_to? :specification_version then