commit 2ab4529daad2fd133d91379ce94a297d037fd372 Author: Bryn M. Reeves Date: Wed Dec 19 21:06:19 2012 +0000 Preserve ownership and permission on copied files Preserve the ownership and permission information for collected files by using shutil.copy2 instead of copyfileobj() and calling os.chown() after copying. diff --git a/sos/plugintools.py b/sos/plugintools.py index 39b2368..ea29ea9 100644 --- a/sos/plugintools.py +++ b/sos/plugintools.py @@ -232,11 +232,9 @@ class PluginBase: linkto = os.readlink(src) os.symlink(linkto, new_fname) else: - fsrc = open(src,'r') - fdst = open(new_fname, 'w') - shutil.copyfileobj(fsrc, fdst, -1) - fsrc.close() - fdst.close() + shutil.copy2(src, new_fname) + stat = os.stat(src) + os.chown(new_fname, stat.st_uid, stat.st_gid) else: raise PluginException('Error copying file: already exists')