diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-01-16 12:48:50 +0100 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-01-16 12:48:58 +0100 |
commit | 4ae4a4799e52f9382560388a3c08296f5e596db9 (patch) | |
tree | aca89b83536edb9a53b3c2c83be3e8685e5e7858 /app | |
parent | 267ce96e36ecec169b02410bfea85e6d31715910 (diff) | |
download | gitlab-ce-4ae4a4799e52f9382560388a3c08296f5e596db9.tar.gz |
Update pages config only when changed
Diffstat (limited to 'app')
-rw-r--r-- | app/services/projects/update_pages_configuration_service.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/app/services/projects/update_pages_configuration_service.rb b/app/services/projects/update_pages_configuration_service.rb index abf40b3ad7a..43eb110c994 100644 --- a/app/services/projects/update_pages_configuration_service.rb +++ b/app/services/projects/update_pages_configuration_service.rb @@ -9,8 +9,10 @@ module Projects end def execute - update_file(pages_config_file, pages_config.to_json) - reload_daemon + if update_file(pages_config_file, pages_config.to_json) + reload_daemon + end + success rescue => e error(e.message) @@ -69,7 +71,12 @@ module Projects def update_file(file, data) unless data FileUtils.remove(file, force: true) - return + return true + end + + existing_data = read_file(file) + if data == existing_data + return false end temp_file = "#{file}.#{SecureRandom.hex(16)}" @@ -77,9 +84,19 @@ module Projects f.write(data) end FileUtils.move(temp_file, file, force: true) + + true ensure # In case if the updating fails FileUtils.remove(temp_file, force: true) end + + def read_file(file) + File.open(file, 'r') do |f| + f.read + end + rescue + nil + end end end |