atomic_write: create path before writing file

This commit is contained in:
Jörg Thalheim 2015-01-15 09:06:01 +01:00
parent bdcc3e2be5
commit a03bb44e10

View File

@ -19,6 +19,10 @@ class Registry
end end
def atomic_write(path, content) def atomic_write(path, content)
dir = File.dirname(path)
unless Dir.exist?(dir)
FileUtils.mkdir_p(dir)
end
temp_path = path.to_s + ".tmp" temp_path = path.to_s + ".tmp"
File.open(temp_path, 'w+') do |f| File.open(temp_path, 'w+') do |f|
f.write(content) f.write(content)