factoids: safer DB writes
This commit is contained in:
parent
fb0b0c4cf0
commit
4b10ea7ab0
@ -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 -----------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user