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.
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user