From 76457eff167f9e4ef0928e8c3bf6c5c869e8fa93 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Feb 2013 10:34:43 -0800 Subject: [PATCH] Make sure the state file only contains unique fields --- plugins/commands/plugin/state_file.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/commands/plugin/state_file.rb b/plugins/commands/plugin/state_file.rb index ce045507f..0371f74cd 100644 --- a/plugins/commands/plugin/state_file.rb +++ b/plugins/commands/plugin/state_file.rb @@ -10,15 +10,17 @@ module VagrantPlugins @data = {} @data = JSON.parse(@path.read) if @path.exist? + @data["installed"] ||= [] end # Add a plugin that is installed to the state file. # # @param [String] name The name of the plugin def add_plugin(name) - @data["installed"] ||= [] - @data["installed"] << name - save! + if !@data["installed"].include?(name) + @data["installed"] << name + save! + end end # This returns a list of installed plugins according to the state @@ -27,12 +29,15 @@ module VagrantPlugins # # @return [Array] def installed_plugins - @data["installed"] ||= [] @data["installed"] end # This saves the state back into the state file. def save! + # Scrub some fields + @data["installed"].uniq! + + # Save @path.open("w+") do |f| f.write(JSON.dump(@data)) end