factoids: safer DB writes

This commit is contained in:
Přemysl Eric Janouch 2016-02-29 03:15:44 +01:00
parent fb0b0c4cf0
commit 4b10ea7ab0
1 changed files with 4 additions and 1 deletions

View File

@ -58,10 +58,13 @@ sub db_load {
sub db_save {
local $\ = "\n";
my ($path, $ref) = @_;
open my $db, ">", $path or die "db save failed: $!";
my $path_new = "$path.new";
open my $db, ">", $path_new or die "db save failed: $!";
my %entries = %$ref;
print $db join "\r", ($_, @{$entries{$_}}) for keys %entries;
close $db;
rename $path_new, $path or die "db save failed: $!";
}
# --- Factoids -----------------------------------------------------------------