aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-12-06 18:33:11 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-12-06 18:33:11 +0000
commitccd3255fac25b982673fc0a785d4be4892b3f141 (patch)
tree575231a845d17e785cf2413ad028c9918db725fe
parentaab9f1f06304a03190787bbb8ef1f7e2871a8572 (diff)
downloadsos-ccd3255fac25b982673fc0a785d4be4892b3f141.tar.gz
Handle non-readable files better in doCopyFileOrDir
Currently a non-readable file causes an exception and resulting error logging as the path is passed blindly to archive.add_file(). There are legitimate reasons why directories colleceted by sos may contain files not readable by root, e.g. in sysfs where there are numerous write-only trigger files. Check the permissions via os.stat() before reading the file and substitute unreadable files with the empty string.
-rw-r--r--sos/plugins/__init__.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 3378712f..57a61acb 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -319,7 +319,13 @@ class Plugin(object):
self.soslog.debug("copying file %s to %s" % (srcpath,dest))
try:
- self.archive.add_file(srcpath, dest)
+ stat = os.stat(srcpath)
+ # if not readable(srcpath)
+ if not (stat.st_mode & 0444):
+ # FIXME: reflect permissions in archive
+ self.archive.add_string("", dest)
+ else:
+ self.archive.add_file(srcpath, dest)
self.copiedFiles.append({
'srcpath':srcpath,