From 99406adaaee52706201c4277051f4226c1160583 Mon Sep 17 00:00:00 2001 From: Jörg Thalheim Date: Wed, 23 Sep 2020 10:47:39 +0200 Subject: 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. --- nixos/modules/config/update-users-groups.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nixos/modules/config/update-users-groups.pl b/nixos/modules/config/update-users-groups.pl index ddd7efd82f7..86107abae36 100644 --- a/nixos/modules/config/update-users-groups.pl +++ b/nixos/modules/config/update-users-groups.pl @@ -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; } -- cgit 1.4.1