Merge pull request #7550 from cgwalters/plugin-atomic-rewrite

plugin: Write out state file via create-new-then-rename
This commit is contained in:
Seth Vargo 2016-07-18 21:58:23 -04:00 committed by GitHub
commit ea17ad4530
1 changed files with 6 additions and 1 deletions

View File

@ -1,4 +1,6 @@
require "json"
require "fileutils"
require "tempfile"
module Vagrant
module Plugin
@ -91,8 +93,11 @@ module Vagrant
# 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.write(JSON.dump(@data))
f.chmod(0644)
f.close
FileUtils.mv(f.path, @path)
end
end