diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2017-10-19 16:34:04 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2017-10-19 16:34:04 +0100 |
commit | ae76de192e6c7a42e4515971249298decd602f54 (patch) | |
tree | ccdba0f67c6c26b5e2490f41662d110b388bea56 | |
parent | 55800f71bdcfdea22b1d6e1c68848e58eb087d1c (diff) | |
download | sos-ae76de192e6c7a42e4515971249298decd602f54.tar.gz |
[Plugin] reverse sort file list when size limiting
Reverse sort the file list by modification time, to ensure that
the most recent data is included when limits apply.
Fixes: #1082
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index f24f27ea..61a3083e 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -534,10 +534,19 @@ class Plugin(object): copyspec = self.join_sysroot(copyspec) files = self._expand_copy_spec(copyspec) - files.sort() + if len(files) == 0: continue + # Files hould be sorted in most-recently-modified order, so that + # we collect the newest data first before reaching the limit. + def getmtime(path): + try: + return os.path.getmtime(path) + except (OSError, FileNotFoundError): + return 0 + + files.sort(key=getmtime, reverse=True) current_size = 0 limit_reached = False _file = None |