Commit c6723ed3 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Updated configuration saving

parent 7f12cb0e
...@@ -7,7 +7,7 @@ module Projects ...@@ -7,7 +7,7 @@ module Projects
end end
def execute def execute
update_file(pages_config_file, pages_config) update_file(pages_config_file, pages_config.to_json)
reload_daemon reload_daemon
success success
rescue => e rescue => e
...@@ -52,18 +52,18 @@ module Projects ...@@ -52,18 +52,18 @@ module Projects
def update_file(file, data) def update_file(file, data)
unless data unless data
File.rm(file, force: true) FileUtils.remove(file, force: true)
return return
end end
temp_file = "#{file}.#{SecureRandom.hex(16)}" temp_file = "#{file}.#{SecureRandom.hex(16)}"
File.open(temp_file, 'w') do |file| File.open(temp_file, 'w') do |f|
file.write(data) f.write(data)
end end
File.mv(temp_file, file, force: true) FileUtils.move(temp_file, file, force: true)
ensure ensure
# In case if the updating fails # In case if the updating fails
File.rm(temp_file, force: true) FileUtils.remove(temp_file, force: true)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment