Module: check_mk
Branch: master
Commit: c0a991f33db64fea3b2c511e9604eca91788860c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c0a991f33db64f…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Apr 8 09:03:03 2016 +0200
Remove file race condition when saving annotations
---
web/htdocs/availability.py | 4 +++-
web/plugins/views/availability.py | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/web/htdocs/availability.py b/web/htdocs/availability.py
index 5e0f654..6b94c39 100644
--- a/web/htdocs/availability.py
+++ b/web/htdocs/availability.py
@@ -955,7 +955,9 @@ def melt_short_intervals(entries, duration, dont_merge):
def save_annotations(annotations):
- file(defaults.var_dir + "/availability_annotations.mk",
"w").write(repr(annotations) + "\n")
+ path = defaults.var_dir + "/availability_annotations.mk"
+ file(path + ".new", "w").write(repr(annotations) +
"\n")
+ os.rename(path + ".new", path)
def load_annotations(lock = False):
diff --git a/web/plugins/views/availability.py b/web/plugins/views/availability.py
index 4780b80..fbe2d46 100644
--- a/web/plugins/views/availability.py
+++ b/web/plugins/views/availability.py
@@ -28,8 +28,6 @@
#
# - Host-Downtimes müssen auch auf Services wirken
# - Test mit Hosts und BI-Aggregaten
-# - Wenn man Reload macht nach dem Speichern in einer Annotation, landet man
-# wieder in der Maske.
# - Wenn man eine Annotation gelöscht hat, braucht man erst einen Reload,
# damit die Zeitleiste korrekt dargestellt wird. Anscheinend haben wir
# hier ein Reihenfolgenproblem.
@@ -726,6 +724,7 @@ def edit_annotation():
# Called at the beginning of every availability page
def handle_delete_annotations():
+ html.debug(u"Ich lösche")
if html.var("_delete_annotation"):
site_id = html.var("anno_site") or ""
hostname = html.var("anno_host")
@@ -745,6 +744,7 @@ def handle_delete_annotations():
availability.delete_annotation(annotations, site_host_svc, fromtime, untiltime)
availability.save_annotations(annotations)
+
def handle_edit_annotations():
# Avoid reshowing edit form after edit and reload
if html.is_transaction() and not html.transaction_valid():