Blame SOURCES/sos-bz1906598-collect-broken-symlinks.patch

f2c821
From 15e54577289a29e72c636f8987859e91c3a55a7c Mon Sep 17 00:00:00 2001
f2c821
From: Pavel Moravec <pmoravec@redhat.com>
f2c821
Date: Thu, 10 Dec 2020 20:23:03 +0100
f2c821
Subject: [PATCH] [report] collect broken symlinks
f2c821
f2c821
Information about broken symlink destination is useful information
f2c821
that sos report should collect. Currently it stops doing so as
f2c821
stat-ing the symlink to determine filesize fails.
f2c821
f2c821
Closes: #2333
f2c821
Resolves: #2338
f2c821
f2c821
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
f2c821
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
f2c821
---
f2c821
 sos/report/plugins/__init__.py | 16 ++++++++++------
f2c821
 1 file changed, 10 insertions(+), 6 deletions(-)
f2c821
f2c821
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py
f2c821
index 510e116e..1527caea 100644
f2c821
--- a/sos/report/plugins/__init__.py
f2c821
+++ b/sos/report/plugins/__init__.py
f2c821
@@ -1449,11 +1449,16 @@ class Plugin(object):
f2c821
                     continue
f2c821
 
f2c821
                 try:
f2c821
-                    filestat = os.stat(_file)
f2c821
+                    file_size = os.stat(_file)[stat.ST_SIZE]
f2c821
                 except OSError:
f2c821
-                    self._log_info("failed to stat '%s'" % _file)
f2c821
-                    continue
f2c821
-                current_size += filestat[stat.ST_SIZE]
f2c821
+                    # if _file is a broken symlink, we should collect it,
f2c821
+                    # otherwise skip it
f2c821
+                    if os.path.islink(_file):
f2c821
+                        file_size = 0
f2c821
+                    else:
f2c821
+                        self._log_info("failed to stat '%s', skipping" % _file)
f2c821
+                        continue
f2c821
+                current_size += file_size
f2c821
 
f2c821
                 if sizelimit and current_size > sizelimit:
f2c821
                     limit_reached = True
f2c821
@@ -1467,8 +1472,7 @@ class Plugin(object):
f2c821
                         strfile = (
f2c821
                             file_name.replace(os.path.sep, ".") + ".tailed"
f2c821
                         )
f2c821
-                        add_size = (sizelimit + filestat[stat.ST_SIZE]
f2c821
-                                    - current_size)
f2c821
+                        add_size = sizelimit + file_size - current_size
f2c821
                         self.add_string_as_file(tail(_file, add_size), strfile)
f2c821
                         rel_path = os.path.relpath('/', os.path.dirname(_file))
f2c821
                         link_path = os.path.join(rel_path, 'sos_strings',
f2c821
-- 
f2c821
2.26.2
f2c821