If the data store is empty, delete the backing file
This commit is contained in:
parent
e4cb2749a1
commit
9590928553
|
@ -25,8 +25,11 @@ module Vagrant
|
||||||
return if !file_path
|
return if !file_path
|
||||||
|
|
||||||
clean_nil_and_empties
|
clean_nil_and_empties
|
||||||
File.open(file_path, "w") do |f|
|
|
||||||
f.write(to_json)
|
if empty?
|
||||||
|
File.delete(file_path) if File.file?(file_path)
|
||||||
|
else
|
||||||
|
File.open(file_path, "w") { |f| f.write(to_json) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class DataStoreTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
File.delete(@db_file)
|
File.delete(@db_file) if File.file?(@db_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be a hash with indifferent access" do
|
should "be a hash with indifferent access" do
|
||||||
|
@ -39,6 +39,17 @@ class DataStoreTest < Test::Unit::TestCase
|
||||||
assert_equal "changed", @klass.new(@db_file)[:foo]
|
assert_equal "changed", @klass.new(@db_file)[:foo]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "delete the data store file if the hash is empty" do
|
||||||
|
@instance[:foo] = :bar
|
||||||
|
@instance.commit
|
||||||
|
assert File.exist?(@db_file)
|
||||||
|
|
||||||
|
@instance.clear
|
||||||
|
assert @instance.empty?
|
||||||
|
@instance.commit
|
||||||
|
assert !File.exist?(@db_file)
|
||||||
|
end
|
||||||
|
|
||||||
should "clean nil and empties if commit is called" do
|
should "clean nil and empties if commit is called" do
|
||||||
@instance[:foo] = { :bar => nil }
|
@instance[:foo] = { :bar => nil }
|
||||||
@instance[:bar] = {}
|
@instance[:bar] = {}
|
||||||
|
|
Loading…
Reference in New Issue