Skip to content

Commit

Permalink
Use net-scp rather than unison
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdavidlaing committed Apr 26, 2013
1 parent 358a57c commit 55e846b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
38 changes: 32 additions & 6 deletions lib/vagrant-unison/command.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "log4r"
require "vagrant"
require 'listen'
require 'net/ssh'
require 'net/scp'

module VagrantPlugins
module Unison
Expand All @@ -10,18 +12,42 @@ def execute

with_target_vms do |machine|
hostpath, guestpath = init_paths machine

ssh_info = machine.ssh_info

# Create the guest path
machine.communicate.sudo("mkdir -p '#{guestpath}'")
machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'")

trigger_unison_sync machine
#copy up everything at the beginning
Net::SCP.start(ssh_info[:host], ssh_info[:username],
{ :port => ssh_info[:port],
:keys => [ ssh_info[:private_key_path],
:paranoid => false ] }) do |scp|
scp.upload! hostpath, guestpath, :recursive => true
end

@env.ui.info "Watching #{hostpath} for changes..."

Listen.to(hostpath) do |modified, added, removed|
@env.ui.info "Detected modifications to #{modified.inspect}" unless modified.empty?
@env.ui.info "Detected new files #{added.inspect}" unless added.empty?
@env.ui.info "Detected deleted files #{removed.inspect}" unless removed.empty?

trigger_unison_sync machine
Net::SCP.start(ssh_info[:host], ssh_info[:username],
{ :port => ssh_info[:port],
:keys => [ ssh_info[:private_key_path],
:paranoid => false ] }) do |scp|
(modified_list << added_list).flatten.each do |file|
remote_file = file.gsub(hostpath, guestpath)
@env.ui.info "Uploading #{file} to #{remote_file}"
scp.upload! file, remote_file
end
removed.each do |file|
remote_file = file.gsub(hostpath, guestpath)
@env.ui.info "Deleting #{remote_file}"
machine.communicate.sudo("rm #{remote_file}")
end
end

end

end

0 #all is well
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-unison/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module Unison
VERSION = "0.0.6"
VERSION = "0.0.7"
end
end
1 change: 1 addition & 0 deletions vagrant-unison.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency "listen", "~> 0.7.3"
s.add_runtime_dependency "rb-fsevent", "~> 0.9"
s.add_runtime_dependency "net-scp", "~> 1.1.0"

s.add_development_dependency "rake"
s.add_development_dependency "rspec-core", "~> 2.12.2"
Expand Down

0 comments on commit 55e846b

Please sign in to comment.