lib/vagrant/plugin/state_file.rb in vagrant-unbundled-1.8.4.2 vs lib/vagrant/plugin/state_file.rb in vagrant-unbundled-1.8.5.1
- old
+ new
@@ -1,6 +1,8 @@
require "json"
+require "fileutils"
+require "tempfile"
module Vagrant
module Plugin
# This is a helper to deal with the plugin state file that Vagrant
# uses to track what plugins are installed and activated and such.
@@ -89,11 +91,16 @@
@data["sources"] || []
end
# This saves the state back into the state file.
def save!
- @path.open("w+") do |f|
+ Tempfile.open(@path.basename.to_s, @path.dirname.to_s) do |f|
+ f.binmode
f.write(JSON.dump(@data))
+ f.fsync
+ f.chmod(0644)
+ f.close
+ FileUtils.mv(f.path, @path)
end
end
protected