aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2014-04-06 14:15:24 +0100
committerBryn M. Reeves <bmr@redhat.com>2014-04-06 14:15:24 +0100
commit5c8ad1bf85400aaacb82a478304bb77661d726a1 (patch)
treed751eb7ca78274d1d50c25306b2363130dfe5d94
parent8b30bc8e3ca0a8721a733757a972b16f9d74f269 (diff)
downloadsos-5c8ad1bf85400aaacb82a478304bb77661d726a1.tar.gz
Break up exception handling in FileCacheArchive.add_file()
An exception can occur at several points in add_file() - Copying the source to the destination - Propagating permissions with shutil.copystat - Setting ownership via os.chown The second of these can occur when copying SELinux xattrs from /proc. Separate out the three cases and ignore failures in copystat. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/archive.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/sos/archive.py b/sos/archive.py
index 3cca9b7c..cdc1f35e 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -118,11 +118,18 @@ class FileCacheArchive(Archive):
self._check_path(dest)
try:
shutil.copy(src, dest)
+ except IOError:
+ self.log.info("caught IO error copying %s" % src)
+ try:
shutil.copystat(src, dest)
+ except PermissionError:
+ # SELinux xattrs in /proc and /sys throw this
+ pass
+ try:
stat = os.stat(src)
os.chown(dest, stat.st_uid, stat.st_gid)
- except IOError:
- self.log.info("caught IO error copying %s" % src)
+ except Exception as e:
+ self.log.debug("caught %s setting ownership of %s" % (e,dest))
self.log.debug("added %s to FileCacheArchive %s" %
(src, self._archive_root))