Skip to content

Commit 29bff30

Browse files
committed
[utilities] Treat audit logs as text files, not binary
Audit logs contain 0x1d separator as a valid character, what makes magic library to treat the files as binary. Exclude audit logs from marking them as binary. Relevant: #4266 Closes: #4276 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
1 parent 3432917 commit 29bff30

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sos/utilities.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,13 @@ def file_is_binary(fname):
171171
try:
172172
_ftup = magic.detect_from_filename(fname)
173173
_mimes = ['text/', 'inode/']
174+
# since `magic` (as well as "file" cmd) treats audit logs as
175+
# binary files due to 0x1d separator, we need to explicitly mark
176+
# audit.log and audit.log.[1-9]* as non-binary
174177
return (
175178
_ftup.encoding == 'binary' and not
176-
any(_ftup.mime_type.startswith(_mt) for _mt in _mimes)
179+
any(_ftup.mime_type.startswith(_mt) for _mt in _mimes) and not
180+
bool(re.search(r'audit\.log(?:\.[1-9]\d*)?$', fname))
177181
)
178182
except Exception:
179183
pass

0 commit comments

Comments
 (0)