diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-28 12:29:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-28 12:29:59 +0100 |
commit | 969fe6615ff26fc2ff78b6b2dd853b5a696fe90f (patch) | |
tree | f657a85f5cb784d9f0eaeec67d4b402fdf254d83 /utils | |
parent | 8612942fd478b4728c4acd1f7c91e00d205d91b5 (diff) | |
download | rspamd-969fe6615ff26fc2ff78b6b2dd853b5a696fe90f.tar.gz rspamd-969fe6615ff26fc2ff78b6b2dd853b5a696fe90f.zip |
[Minor] Asn.pl: Fix tempfile creation
Submitted by: @citrin
Diffstat (limited to 'utils')
-rw-r--r-- | utils/asn.pl | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/utils/asn.pl b/utils/asn.pl index fa3cffdb8..61e58d760 100644 --- a/utils/asn.pl +++ b/utils/asn.pl @@ -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; |