From 1110a96d0461657f133736697cc188b9627911f5 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Sun, 14 Aug 2011 09:35:00 +0100 Subject: Truncate files that exceed specified size limit Resolves: bz683219 --- sos/plugintools.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sos/plugintools.py b/sos/plugintools.py index f0c931c1..403e25cd 100644 --- a/sos/plugintools.py +++ b/sos/plugintools.py @@ -286,11 +286,19 @@ class PluginBase: files = glob.glob(fname) files.sort() cursize = 0 + limit_reached = False + sizelimit *= 1024 * 1024 # in MB for flog in files: cursize += os.stat(flog)[ST_SIZE] - if sizelimit and (cursize / 1024 / 1024) > sizelimit: - break - self.addCopySpec(flog) + if sizelimit and cursize > sizelimit: + limit_reached = True + else: + self.addCopySpec(flog) + # Truncate the first file (others would likely be compressed), + # ensuring we get at least some logs + if flog == files[0] and limit_reached: + self.collectExtOutput("tail -c%d %s" % (sizelimit, flog), + "tail_" + os.path.basename(flog)) def addCopySpec(self, copyspec): """ Add a file specification (can be file, dir,or shell glob) to be -- cgit