Module: check_mk
Branch: master
Commit: f17ee3a57788d34749f849690bb69141345035ca
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f17ee3a57788d3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 29 08:28:53 2016 +0200
Changed handling of empty files and name of tempfiles
---
lib/store.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/store.py b/lib/store.py
index 8101918..0783282 100644
--- a/lib/store.py
+++ b/lib/store.py
@@ -188,7 +188,12 @@ def load_data_from_file(path, default=None, lock=False):
try:
try:
- return ast.literal_eval(file(path).read())
+ content = file(path).read().strip()
+ if not content:
+ # May be created empty during locking
+ return default
+ else:
+ return ast.literal_eval(file(path).read())
except IOError, e:
if e.errno == 2: # IOError: [Errno 2] No such file or directory
return default
@@ -212,7 +217,7 @@ def save_file(path, content, mode=0660):
try:
tmp_path = None
with tempfile.NamedTemporaryFile("w", dir=os.path.dirname(path),
- prefix=os.path.basename(path)+".new",
+ prefix=".%s.new" %
os.path.basename(path),
delete=False) as tmp:
tmp_path = tmp.name
os.chmod(tmp_path, mode)