From 5c8ad1bf85400aaacb82a478304bb77661d726a1 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Sun, 6 Apr 2014 14:15:24 +0100 Subject: 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 --- sos/archive.py | 11 +++++++++-- 1 file 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)) -- cgit