summary refs log tree commit diff
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2020-09-23 10:47:39 +0200
committerJörg Thalheim <joerg@thalheim.io>2020-09-23 10:51:01 +0200
commit99406adaaee52706201c4277051f4226c1160583 (patch)
tree67026c27c56fd1541ecfaa10d5721beb7017a431
parentf072d4dadcee0b616927f14baf3feb18591a1d68 (diff)
downloadnixpkgs-99406adaaee52706201c4277051f4226c1160583.tar
nixpkgs-99406adaaee52706201c4277051f4226c1160583.tar.gz
nixpkgs-99406adaaee52706201c4277051f4226c1160583.tar.bz2
nixpkgs-99406adaaee52706201c4277051f4226c1160583.tar.lz
nixpkgs-99406adaaee52706201c4277051f4226c1160583.tar.xz
nixpkgs-99406adaaee52706201c4277051f4226c1160583.tar.zst
nixpkgs-99406adaaee52706201c4277051f4226c1160583.zip
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.
-rw-r--r--nixos/modules/config/update-users-groups.pl3
1 files changed, 1 insertions, 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;
 }