sos/SOURCES/sos-bz1906598-collect-broken-symlinks.patch
2021-10-08 16:52:09 +00:00

57 lines
2.3 KiB
Diff

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