From 89ee04e8f71b2dd19ad1d7b9ae16c68f33b85389 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 6 Dec 2012 20:08:57 +0000 Subject: Preserve permissions and ownership for files stored as strings Files that are stored as strings bypass the permissions code added in commit 74c1476 since they are added to the archive via add_string(). Add a check to see if a destination exists in the host file system. If it does propagate the permissions to the stored string's tar record. --- sos/utilities.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sos/utilities.py b/sos/utilities.py index fa795141..2180aeb2 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -236,10 +236,20 @@ class TarFileArchive(Archive): self.tarfile.addfile(tar_info, StringIO(content)) def add_string(self, content, dest): + fstat = None + if os.path.exists(dest): + fstat = os.stat(dest) dest = self.prepend(dest) tar_info = tarfile.TarInfo(name=dest) tar_info.size = len(content) - tar_info.mtime = time.time() + if fstat: + 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 + else: + tar_info.mtime = time.time() self.tarfile.addfile(tar_info, StringIO(content)) def add_link(self, dest, link_name): -- cgit