aboutsummaryrefslogtreecommitdiff
path: root/plugins/zyklonb
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-02-29 03:15:44 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-02-29 03:15:44 +0100
commit4b10ea7ab0dc1e59fe6957e01b4a54687572ed44 (patch)
tree038c517267429a3d9690a176a3af35de45761599 /plugins/zyklonb
parentfb0b0c4cf068f243982cc650521b16e170f4d9ca (diff)
downloadxK-4b10ea7ab0dc1e59fe6957e01b4a54687572ed44.tar.gz
xK-4b10ea7ab0dc1e59fe6957e01b4a54687572ed44.tar.xz
xK-4b10ea7ab0dc1e59fe6957e01b4a54687572ed44.zip
factoids: safer DB writes
Diffstat (limited to 'plugins/zyklonb')
-rwxr-xr-xplugins/zyklonb/factoids5
1 files changed, 4 insertions, 1 deletions
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 -----------------------------------------------------------------