From 4b10ea7ab0dc1e59fe6957e01b4a54687572ed44 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Mon, 29 Feb 2016 03:15:44 +0100
Subject: factoids: safer DB writes
---
plugins/zyklonb/factoids | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/plugins/zyklonb/factoids b/plugins/zyklonb/factoids
index 00a9fbf..8bf2dc0 100755
--- a/plugins/zyklonb/factoids
+++ b/plugins/zyklonb/factoids
@@ -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 -----------------------------------------------------------------
--
cgit v1.2.3-70-g09d2