Skip to content

Commit

Permalink
Implemented vagrant sync-cleanup
Browse files Browse the repository at this point in the history
Fixes mrdavidlaing#14
Run it after you do "vagrant destroy; vagrant up"
  • Loading branch information
dmatora committed Jan 9, 2015
1 parent 90e254a commit ffe2c8f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ which must be installed in your path.

Run `vagrant sync-repeat` to start in bidirect monitor (repeat) mode.

## Cleanup unison database
When you get
```
Fatal error: Warning: inconsistent state.
The archive file is missing on some hosts.
For safety, the remaining copies should be deleted.
Archive arb126d8de1ef26a835b94cf51975c530f on host blablabla.local should be DELETED
Archive arbc6a36f85b3d1473c55565dd220acf68 on host blablabla is MISSING
Please delete archive files as appropriate and try again
or invoke Unison with -ignorearchives flag.
```

Run `vagrant sync-cleanup` to clear Archive from ~/Library/Application Support/Unison/ and files from host folder.
Running Unison with -ignorearchives flag is a bad idea, since it will produce conflicts.

## Development

To work on the `vagrant-unison` plugin, clone this repository out, and use
Expand Down
38 changes: 37 additions & 1 deletion lib/vagrant-unison/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,43 @@ def trigger_unison_sync(machine)
].flatten.join(" ")

# Unison over to the guest path using the SSH info
command = "unison -terse -repeat 1 -sshargs \"#{rsh}\" hosts ssh://#{ssh_info[:username]}@#{ssh_info[:host]}/#{guestpath}"
command = 'unison -ignore "Name {.idea}" -terse -repeat 1 -sshargs "'+rsh+'" hosts '+"ssh://#{ssh_info[:username]}@#{ssh_info[:host]}/#{guestpath}"
@env.ui.info "Running #{command}"

system(command)
end

end
class CommandCleanup < Vagrant.plugin("2", :command)

def execute

with_target_vms do |machine|
hostpath, guestpath = init_paths machine

trigger_unison_sync machine

end

0 #all is well
end

def init_paths(machine)
hostpath = File.expand_path(machine.config.sync.host_folder, @env.root_path)
guestpath = machine.config.sync.guest_folder

# Make sure there is a trailing slash on the host path to
# avoid creating an additional directory with rsync
hostpath = "#{hostpath}/" if hostpath !~ /\/$/

[hostpath, guestpath]
end

def trigger_unison_sync(machine)
hostpath, guestpath = init_paths machine

# Unison over to the guest path using the SSH info
command = "rm -rf ~/Library/'Application Support'/Unison/* ; rm -rf #{guestpath}/*"
@env.ui.info "Running #{command}"

system(command)
Expand Down
10 changes: 10 additions & 0 deletions lib/vagrant-unison/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class Plugin < Vagrant.plugin("2")
CommandRepeat
end

command "sync-cleanup" do
# Setup logging and i18n
setup_logging
setup_i18n

#Return the command
require_relative "command"
CommandCleanup
end

# This initializes the internationalization strings.
def self.setup_i18n
I18n.load_path << File.expand_path("locales/en.yml", Unison.source_root)
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.12"
VERSION = "0.0.13"
end
end

0 comments on commit ffe2c8f

Please sign in to comment.