plugin: Write out state file via create-new-then-rename

This makes updates atomic, so it's useful generally.  However
I'm making this change specifically to support rpm-ostree.

For more information, see:
https://bugzilla.redhat.com/show_bug.cgi?id=1352152
This commit is contained in:
Colin Walters 2016-07-05 15:28:02 -04:00
parent a4f45a18a6
commit 72c1972181
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