Commit 4ae4a479 authored by Kamil Trzciński's avatar Kamil Trzciński

Update pages config only when changed

parent 267ce96e
...@@ -9,8 +9,10 @@ module Projects ...@@ -9,8 +9,10 @@ module Projects
end end
def execute def execute
update_file(pages_config_file, pages_config.to_json) if update_file(pages_config_file, pages_config.to_json)
reload_daemon reload_daemon
end
success success
rescue => e rescue => e
error(e.message) error(e.message)
...@@ -69,7 +71,12 @@ module Projects ...@@ -69,7 +71,12 @@ module Projects
def update_file(file, data) def update_file(file, data)
unless data unless data
FileUtils.remove(file, force: true) FileUtils.remove(file, force: true)
return return true
end
existing_data = read_file(file)
if data == existing_data
return false
end end
temp_file = "#{file}.#{SecureRandom.hex(16)}" temp_file = "#{file}.#{SecureRandom.hex(16)}"
...@@ -77,9 +84,19 @@ module Projects ...@@ -77,9 +84,19 @@ module Projects
f.write(data) f.write(data)
end end
FileUtils.move(temp_file, file, force: true) FileUtils.move(temp_file, file, force: true)
true
ensure ensure
# In case if the updating fails # In case if the updating fails
FileUtils.remove(temp_file, force: true) FileUtils.remove(temp_file, force: true)
end end
def read_file(file)
File.open(file, 'r') do |f|
f.read
end
rescue
nil
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