From 5894959e00a7838bce8f89eb807ea6c2299cfba9 Mon Sep 17 00:00:00 2001 From: dmatora Date: Fri, 9 Jan 2015 04:07:17 +0300 Subject: [PATCH] Implemented vagrant sync-cleanup Fixes http://mrdavidlaing/vagrant-unison#14 Run it after you do "vagrant destroy; vagrant up" --- README.md | 15 ++++++++++++++ lib/vagrant-unison/command.rb | 38 ++++++++++++++++++++++++++++++++++- lib/vagrant-unison/plugin.rb | 10 +++++++++ lib/vagrant-unison/version.rb | 2 +- 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 883ec23..081524c 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/vagrant-unison/command.rb b/lib/vagrant-unison/command.rb index 33f832a..f3e4617 100644 --- a/lib/vagrant-unison/command.rb +++ b/lib/vagrant-unison/command.rb @@ -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) diff --git a/lib/vagrant-unison/plugin.rb b/lib/vagrant-unison/plugin.rb index f8b7ea8..cbf4b3a 100644 --- a/lib/vagrant-unison/plugin.rb +++ b/lib/vagrant-unison/plugin.rb @@ -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) diff --git a/lib/vagrant-unison/version.rb b/lib/vagrant-unison/version.rb index 963644e..4ade27e 100644 --- a/lib/vagrant-unison/version.rb +++ b/lib/vagrant-unison/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Unison - VERSION = "0.0.12" + VERSION = "0.0.13" end end