Add Logic to detect file type by extension

Fedabipkgdiff uses mimetypes to detect what file type it is looking
at. In some minimal versions of the OS, in particular container
images, the package that includes all the mimetypes may not be
installed. This allows fedabipkgdiff to fall back to using the
extension.

    * tools/fedabipkgdiff - add logic to detect file type by extension

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
Reviewed-by: Ben Woodard <woodard@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
vsoch 2022-05-04 12:51:38 -07:00 committed by Dodji Seketeli
parent c7a71ba2d1
commit 707e47f4ce

View File

@ -213,6 +213,10 @@ def is_rpm_file(filename):
mimetype = mimetypes.guess_type(filename)[0] if isfile else None
isrpm = (mimetype == 'application/x-redhat-package-manager'
or mimetype == 'application/x-rpm')
# Most systems won't have rpm defined as a mimetype
if not mimetype and filename.endswith('.rpm'):
isrpm = True
logger.debug('is_rpm_file(\'%s\'): isfile=%s, mimetype=\'%s\', isrpm=%s',
filename, isfile, mimetype, isrpm)
return isrpm