Thank you for sponsoring the patch into Kinetic Eric!
For bionic and focal, we decided to remove the python3-magic call for binary file detection, so for eg. this patch is added for bionic (and a similar one for focal) to revert to the older way. We still keep that function (file_is_binary() ) in utilities as is the case in 4.4, but the way it does binary file detection is reverted to 4.3 approach. Accordingly, we removed the magic stuff from requirements.txt and setup.py too. Please do let me know if you think it should remain in there for reasons we may have overlooked! We have let it remain though in snap/snapcraft.yaml and sos.spec.
~~~
Description: Revert to old way of binary file detection
Reverting to older (4.3) way of detecting binary files
because sos 4.4 uses python3-magic version 0.4.20 which is
not present in bionic.
.
sosreport (4.4-1ubuntu0.18.04.1) bionic; urgency=medium
.
* New 4.4 upstream. (LP: #1986611)
.
* For more details, full release note is available here:
- https://github.com/sosreport/sos/releases/tag/4.4
.
* Former patches, now fixed:
- d/p/0002-fix-setup-py.patch
- d/p/0003-mention-sos-help-in-sos-manpage.patch
.
* Remaining patches:
- d/p/0001-debian-change-tmp-dir-location.patch
.
* New patches:
- d/p/0002-revert-to-old-style-binary-file-detection.patch
Author: Nikhil Kshirsagar <email address hidden>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1986611
from contextlib import closing
from collections import deque
@@ -75,17 +74,14 @@ def file_is_binary(fname):
:returns: True if binary, else False
:rtype: ``bool``
"""
- try:
- _ftup = magic.detect_from_filename(fname)
- _mimes = ['text/', 'inode/']
- return (
- _ftup.encoding == 'binary' and not
- any(_ftup.mime_type.startswith(_mt) for _mt in _mimes)
- )
- except Exception:
- # if for some reason this check fails, don't blindly remove all files
- # but instead rely on other checks done by the component
- return False
+ with open(fname, 'tr') as tfile:
+ try:
+ # when opened as above (tr), reading binary content will raise
+ # an exception
+ tfile.read(1)
+ return False
+ except UnicodeDecodeError:
+ return True
Thank you for sponsoring the patch into Kinetic Eric!
For bionic and focal, we decided to remove the python3-magic call for binary file detection, so for eg. this patch is added for bionic (and a similar one for focal) to revert to the older way. We still keep that function (file_is_binary() ) in utilities as is the case in 4.4, but the way it does binary file detection is reverted to 4.3 approach. Accordingly, we removed the magic stuff from requirements.txt and setup.py too. Please do let me know if you think it should remain in there for reasons we may have overlooked! We have let it remain though in snap/snapcraft.yaml and sos.spec.
~~~ 18.04.1) bionic; urgency=medium /github. com/sosreport/ sos/releases/ tag/4.4 fix-setup- py.patch mention- sos-help- in-sos- manpage. patch debian- change- tmp-dir- location. patch revert- to-old- style-binary- file-detection. patch /bugs.launchpad .net/bugs/ 1986611
Description: Revert to old way of binary file detection
Reverting to older (4.3) way of detecting binary files
because sos 4.4 uses python3-magic version 0.4.20 which is
not present in bionic.
.
sosreport (4.4-1ubuntu0.
.
* New 4.4 upstream. (LP: #1986611)
.
* For more details, full release note is available here:
- https:/
.
* Former patches, now fixed:
- d/p/0002-
- d/p/0003-
.
* Remaining patches:
- d/p/0001-
.
* New patches:
- d/p/0002-
Author: Nikhil Kshirsagar <email address hidden>
Bug-Ubuntu: https:/
--- sosreport- 4.4.orig/ requirements. txt 4.4/requirement s.txt magic>= 0.4.20 4.4.orig/ setup.py 4.4/setup. py cmdclass, options= command_ options, ['pexpect' , 'python_magic', 'pyyaml'] ['pexpect' , 'pyyaml']
+++ sosreport-
@@ -2,5 +2,4 @@ pycodestyle>=2.4.0
coverage>=4.0.3
Sphinx>=1.3.5
pexpect>=4.0.0
-python_
pyyaml
--- sosreport-
+++ sosreport-
@@ -107,7 +107,7 @@ setup(
],
cmdclass=
command_
- requires=
+ requires=
)
--- sosreport- 4.4.orig/ sos/utilities. py 4.4/sos/ utilities. py
+++ sosreport-
@@ -19,7 +19,6 @@ import tempfile
import threading
import time
import io
-import magic
from contextlib import closing binary( fname): from_filename( fname) mime_type. startswith( _mt) for _mt in _mimes)
from collections import deque
@@ -75,17 +74,14 @@ def file_is_
:returns: True if binary, else False
:rtype: ``bool``
"""
- try:
- _ftup = magic.detect_
- _mimes = ['text/', 'inode/']
- return (
- _ftup.encoding == 'binary' and not
- any(_ftup.
- )
- except Exception:
- # if for some reason this check fails, don't blindly remove all files
- # but instead rely on other checks done by the component
- return False
+ with open(fname, 'tr') as tfile:
+ try:
+ # when opened as above (tr), reading binary content will raise
+ # an exception
+ tfile.read(1)
+ return False
+ except UnicodeDecodeError:
+ return True
def find(file_pattern, top_dir, max_depth=None, path_pattern=None):
~~~