aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2013-06-07 17:15:09 +0100
committerBryn M. Reeves <bmr@redhat.com>2013-06-07 17:15:09 +0100
commit9ddb154d609af6c57c8c8ede7d7d7fc9932a2ee8 (patch)
treeb498563a035a1c72cd9af8d2fce7bdc6a664fd28
parent3946e7d80a615b05911db3d6bb7f59b7d27c8cfe (diff)
downloadsos-9ddb154d609af6c57c8c8ede7d7d7fc9932a2ee8.tar.gz
Make SoSReport establish report directory structure
Allow clients of the Archive classes to create arbitrary directories. Sos needs to be able to do this to create the report directory structure within a temporary file system tree. This work also paves the way for improviyng the robustness of the tree copying code in Plugin (which presently relies on the Archive class to recurse up to root, adding parent directories that do not already exist in the archive to ensure the corret permissions and context are stored in the archive). This would also allow the Archive.add_parent() hack to be removed. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/archive.py17
-rw-r--r--sos/sosreport.py6
2 files changed, 21 insertions, 2 deletions
diff --git a/sos/archive.py b/sos/archive.py
index f1b0b057..3702a91f 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -41,6 +41,15 @@ class Archive(object):
_name = "unset"
+ def __init__(self, name, tmpdir):
+ self._name = name
+ self._tmp_dir = tmpdir
+ self._archive_path = os.path.join(tmpdir, name)
+ os.makedirs(self._archive_path, 0700)
+
+ def make_path(self, name):
+ return (os.path.join(self._archive_path, name))
+
def prepend(self, src):
if src:
name = os.path.split(self._name)[-1]
@@ -50,6 +59,10 @@ class Archive(object):
def add_link(self, dest, link_name):
pass
+ def makedirs(self, name, mode=0700):
+ print "Archive.mkdir('%s')" % name
+ os.makedirs(self.make_path(name), mode)
+
def compress(self, method):
"""Compress an archive object via method. ZIP archives are ignored. If
method is automatic then the following technologies are tried in order: xz,
@@ -59,8 +72,8 @@ class Archive(object):
class TarFileArchive(Archive):
- def __init__(self, name):
- self._name = name
+ def __init__(self, name, tmpdir):
+ super(TarFileArchive, self).__init__(name, tmpdir)
self._suffix = "tar"
self.tarfile = tarfile.open(self.name(),
mode="w", format=tarfile.PAX_FORMAT)
diff --git a/sos/sosreport.py b/sos/sosreport.py
index c58f6310..c86acd15 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -569,6 +569,11 @@ class SoSReport(object):
else:
self.archive = TarFileArchive(archive_name, self.opts.tmp_dir)
+ def _make_archive_paths(self):
+ self.archive.makedirs(self.cmddir, 0755)
+ self.archive.makedirs(self.logdir, 0755)
+ self.archive.makedirs(self.rptdir, 0755)
+
def _set_directories(self):
self.cmddir = 'sos_commands'
self.logdir = 'sos_logs'
@@ -915,6 +920,7 @@ class SoSReport(object):
try:
self.policy.pre_work()
self._set_archive()
+ self._make_archive_paths()
except Exception, e:
import traceback
traceback.print_exc(e)