mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 16:03:23 +00:00
nixos/update-users-groups: write files truly atomic
Having the .tmp suffix is broken w.r.t. to multiple writers, as they would overwrite existing files. using the atomic flag will make write_file to create a unique temporary file it gets renamed to its target.
This commit is contained in:
parent
f072d4dadc
commit
99406adaae
@ -16,8 +16,7 @@ my $gidMap = -e $gidMapFile ? decode_json(read_file($gidMapFile)) : {};
|
||||
|
||||
sub updateFile {
|
||||
my ($path, $contents, $perms) = @_;
|
||||
write_file("$path.tmp", { binmode => ':utf8', perms => $perms // 0644 }, $contents);
|
||||
rename("$path.tmp", $path) or die;
|
||||
write_file($path, { atomic => 1, binmode => ':utf8', perms => $perms // 0644 }, $contents) or die;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user