]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Asn.pl: Fix tempfile creation
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 28 Jul 2019 11:29:59 +0000 (12:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 28 Jul 2019 11:29:59 +0000 (12:29 +0100)
Submitted by: @citrin

utils/asn.pl

index fa3cffdb87c4ca4617b45fa5eb8aab825b05d973..61e58d760c066e71f3d9e9f3c28a07a719102c81 100644 (file)
@@ -199,7 +199,11 @@ my $zone_header = << "EOH";
 EOH
 
 if ($v4) {
-    open my $v4_fh, '>', ".$v4_file.tmp";
+    # create temp file in the same dir so we can be sure that mv is atomic
+    my $out_dir = dirname($v4_file);
+    my $out_file = basename($v4_file);
+    my $temp_file = "$out_dir/.$out_file.tmp";
+    open my $v4_fh, '>', $temp_file;
     print $v4_fh $zone_header;
 
     while (my ($net, $asn) = each %{ $networks->{4} }) {
@@ -211,11 +215,14 @@ if ($v4) {
     }
 
     close $v4_fh;
-    rename ".$v4_file.tmp", $v4_file;
+    rename $temp_file, $v4_file;
 }
 
 if ($v6) {
-    open my $v6_fh, '>', ".$v6_file.tmp";
+    my $out_dir = dirname($v6_file);
+    my $out_file = basename($v6_file);
+    my $temp_file = "$out_dir/.$out_file.tmp";
+    open my $v6_fh, '>', $temp_file;
     print $v6_fh $zone_header;
 
     while (my ($net, $asn) = each %{ $networks->{6} }) {
@@ -227,7 +234,7 @@ if ($v6) {
     }
 
     close $v6_fh;
-    rename ".$v6_file.tmp", $v6_file;
+    rename $temp_file, $v6_file;
 }
 
 exit 0;