Module: check_mk
Branch: master
Commit: 0ae4e4dfe33f817321e8cbae46c22c250ca1c10a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0ae4e4dfe33f81…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Nov 8 14:45:22 2016 +0100
store: load func is now unlocking on exception; save is locking at start of write
---
lib/store.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/store.py b/lib/store.py
index de4e057..bb12c59 100644
--- a/lib/store.py
+++ b/lib/store.py
@@ -124,6 +124,9 @@ def load_data_from_file(path, default=None, lock=False):
raise
except Exception, e:
+ if lock:
+ release_lock(path)
+
# TODO: How to handle debug mode or logging?
raise MKGeneralException(_("Cannot read file \"%s\": %s") %
(path, e))
@@ -151,6 +154,10 @@ def save_data_to_file(path, data, pretty=True):
# Then the new file is written to a temporary file and moved to the target path
def save_file(path, content, mode=0660):
try:
+ # Normally the file is already locked (when data has been loaded before with
lock=True),
+ # but lock it just to be sure we have the lock on the file
+ aquire_lock(path)
+
tmp_path = None
with tempfile.NamedTemporaryFile("w", dir=os.path.dirname(path),
prefix=".%s.new" %
os.path.basename(path),