aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-12-06 19:04:47 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-12-06 19:04:47 +0000
commit74c14769675436295fb7009ee6360d438b6c86d7 (patch)
treebff9106a94aed26141abc3190fa79947b5668a75
parentccd3255fac25b982673fc0a785d4be4892b3f141 (diff)
downloadsos-74c14769675436295fb7009ee6360d438b6c86d7.tar.gz
Preserve permissions, ownership and times for files in archive
Stat files during archiving and propagate the mode, atime, uid and gid to the archive. Fixes issue #76
-rw-r--r--sos/utilities.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/sos/utilities.py b/sos/utilities.py
index 3b254c7c..fa795141 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -224,10 +224,14 @@ class TarFileArchive(Archive):
fp = open(src, 'rb')
content = fp.read()
fp.close()
-
+ fstat = os.stat(src)
tar_info = tarfile.TarInfo(name=dest)
tar_info.size = len(content)
- tar_info.mtime = os.stat(src).st_mtime
+ tar_info.mtime = fstat.st_mtime
+ tar_info.pax_headers['atime'] = fstat.st_atime
+ tar_info.mode = fstat.st_mode
+ tar_info.uid = fstat.st_uid
+ tar_info.gid = fstat.st_gid
self.tarfile.addfile(tar_info, StringIO(content))