From f72b9824f3d650ba587a5ff9f82164685fbb0ccf Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 4 Nov 2020 11:39:40 +0100 Subject: [PATCH] Do not overwrite files if they did not change This causes an extra file read, but the benefit is that it is easier to compare data on the file system, quickly see what did actually change and what did not. --- scripts/gitolite/rebuild_gitolite.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/gitolite/rebuild_gitolite.php b/scripts/gitolite/rebuild_gitolite.php index a19be6c898..c549526075 100755 --- a/scripts/gitolite/rebuild_gitolite.php +++ b/scripts/gitolite/rebuild_gitolite.php @@ -24,6 +24,17 @@ function endswith($string, $suffix) { $suffix_length) == $suffix; } +function file_put_contents_if_different($file_name, $content) { + if (file_exists($file_name)) { + $current_content = file_get_contents($file_name); + if ($current_content == $content) { + return; + } + } + + file_put_contents($file_name, $content); +} + //////////////////////////////////////////////////////////////////////////////// // Phabricator access list traversal. @@ -76,8 +87,8 @@ class Configuration { if (!array_key_exists($config_user_name, $this->used_keys)) { $this->used_keys[$config_user_name] = true; - file_put_contents("$this->keys_directory/$config_user_name.pub", - $full_key_content); + file_put_contents_if_different("$this->keys_directory/$config_user_name.pub", + $full_key_content); } return $config_user_name; @@ -110,7 +121,7 @@ class Configuration { $new_config .= $line . "\n"; } - file_put_contents($this->config_file, trim($new_config) . "\n"); + file_put_contents_if_different($this->config_file, trim($new_config) . "\n"); } protected function getNonPhabtricatorUsers($configuration_value) {