Add Logic to detect file type by extension

Message ID
State New
Series Add Logic to detect file type by extension |

Commit Message

Ben Woodard May 4, 2022, 7:24 p.m. UTC
  From: vsoch <>

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

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

Signed-off-by: vsoch <>
Reviewed-by: Ben Woodard <>
 tools/fedabipkgdiff | 4 ++++
 1 file changed, 4 insertions(+)


diff --git a/tools/fedabipkgdiff b/tools/fedabipkgdiff
index dc80a6ef..48a89e03 100755
--- a/tools/fedabipkgdiff
+++ b/tools/fedabipkgdiff
@@ -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'):
+        mimtype = 'application/x-rpm'
     logger.debug('is_rpm_file(\'%s\'): isfile=%s, mimetype=\'%s\', isrpm=%s',
                  filename, isfile, mimetype, isrpm)
     return isrpm