Module: check_mk
Branch: master
Commit: 1153a6986174281903b496fb5905035cbce32546
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1153a698617428…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Aug 18 21:30:09 2011 +0200
cmk --restore: be aware of symbolic links
---
.bugs/43 | 10 +++++++---
ChangeLog | 1 +
modules/check_mk.py | 13 ++++++++++++-
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/.bugs/43 b/.bugs/43
index b599a3c..9bcea86 100644
--- a/.bugs/43
+++ b/.bugs/43
@@ -1,11 +1,15 @@
Title: cmk --restore: cache/ und counters/ können Links sein
Component: core
+State: done
+Class: bug
+Date: 2010-12-21 21:24:30
Benefit: 1
-State: open
Cost: 1
-Date: 2010-12-21 21:24:30
-Class: bug
+Fun: 0
Sicherstellen, dass der --restore nur die Inhalte dieser Verzeichnisse
löscht. Denn wenn es sich hier um Symlinks handelt, würden die beim
Restore durch Verzeichnisse ersetzt werden.
+
+2011-08-18 21:29:35: changed state open -> done
+Jetzt wird der Inhalt explizit gelöscht.
diff --git a/ChangeLog b/ChangeLog
index 3db1c0f..a4a833a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
Core, Setup, etc.:
* FIX: allow host names to have spaces
* --snmpwalk: fix missing space in case of HEX strings
+ * cmk --restore: be aware of counters and cache being symbolic links
Checks & Agents:
* FIX: printer_pages: workaround for trailing-zero bug in HP Jetdirect
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 105c518..9b63256 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2785,7 +2785,18 @@ def do_restore(tarname):
if os.path.exists(absdir):
if opt_verbose:
sys.stderr.write(" Deleting old contents of
'%s'\n" % absdir)
- shutil.rmtree(absdir)
+ # The path might point to a symbalic link. So it is no option
+ # to call shutil.rmtree(). We must delete just the contents
+ for f in os.listdir(absdir):
+ if f not in [ '.', '..' ]:
+ try:
+ p = absdir + "/" + f
+ if os.path.isdir(p):
+ shutil.rmtree(p)
+ else:
+ os.remove(p)
+ except Exception, e:
+ sys.stderr.write(" Warning: cannot delete %s:
%s\n" % (p, e))
else:
basedir = os.path.dirname(absdir)
filename = os.path.basename(absdir)