From 09d2b6fd86cf1cf932b83ecba406b2b4bf537844 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 1 Sep 2014 15:06:51 -0700 Subject: [PATCH] core: add Checkpoint --- lib/vagrant/environment.rb | 23 +++++++++++++++++++++++ test/unit/base.rb | 6 ++++++ vagrant.gemspec | 1 + 3 files changed, 30 insertions(+) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 4541c7e7a..5f70ca1e9 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -4,6 +4,7 @@ require 'pathname' require 'set' require 'thread' +require "checkpoint" require 'log4r' require 'vagrant/util/file_mode' @@ -125,6 +126,18 @@ module Vagrant # Prepare the directories setup_home_path + # Run checkpoint in a background thread on every environment + # initialization. The cache file will cause this to mostly be a no-op + # most of the time. + @checkpoint_thr = Thread.new do + @checkpoint_result = Checkpoint.check( + product: "vagrant", + version: VERSION, + signature_file: @data_dir.join("checkpoint_signature"), + cache_file: @data_dir.join("checkpoint_cache"), + ) + end + # Setup the local data directory. If a configuration path is given, # then it is expanded relative to the working directory. Otherwise, # we use the default which is expanded relative to the root path. @@ -243,6 +256,16 @@ module Vagrant end end + # Checkpoint returns the checkpoint result data. If checkpoint is + # disabled, this will return nil. See the hashicorp-checkpoint gem + # for more documentation on the return value. + # + # @return [Hash] + def checkpoint + @checkpoint_thr.join + return @checkpoint_result + end + # Makes a call to the CLI with the given arguments as if they # came from the real command line (sometimes they do!). An example: # diff --git a/test/unit/base.rb b/test/unit/base.rb index 6866f0f36..3020c7b91 100644 --- a/test/unit/base.rb +++ b/test/unit/base.rb @@ -1,5 +1,8 @@ require "tmpdir" require "rubygems" + +# Gems +require "checkpoint" require "rspec/autorun" # Require Vagrant itself so we can reference the proper @@ -49,3 +52,6 @@ Vagrant.plugin("2").manager.registered.dup.each do |plugin| Vagrant.plugin("2").manager.unregister(plugin) end end + +# Disable checkpoint +Checkpoint.disable! diff --git a/vagrant.gemspec b/vagrant.gemspec index 5392c585a..c4131b270 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |s| s.add_dependency "erubis", "~> 2.7.0" s.add_dependency "i18n", "~> 0.6.0" s.add_dependency "listen", "~> 2.7.1" + s.add_dependency "hashicorp-checkpoint", "~> 0.1.1" s.add_dependency "log4r", "~> 1.1.9", "< 1.1.11" s.add_dependency "net-ssh", ">= 2.6.6", "< 2.10.0" s.add_dependency "net-scp", "~> 1.1.0"