mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +02:00
parent
576135ff8f
commit
47032cb4e9
@ -1452,23 +1452,25 @@ def get_mime_type(path):
|
|||||||
libmagic. Hence this function with the following hacks:
|
libmagic. Hence this function with the following hacks:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
ms = None
|
||||||
try:
|
try:
|
||||||
import magic
|
import magic
|
||||||
ms = None
|
|
||||||
try:
|
try:
|
||||||
ms = magic.open(magic.MIME_TYPE)
|
ms = magic.open(magic.MIME_TYPE)
|
||||||
ms.load()
|
ms.load()
|
||||||
return magic.from_file(path, mime=True)
|
result = magic.from_file(path, mime=True)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return ms.file(path)
|
result = ms.file(path)
|
||||||
if ms is not None:
|
|
||||||
ms.close()
|
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
logging.warn('Found malformed magic number at %s' % path)
|
logging.warn('Found malformed magic number at %s' % path)
|
||||||
|
result = None
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import mimetypes
|
import mimetypes
|
||||||
mimetypes.init()
|
mimetypes.init()
|
||||||
return mimetypes.guess_type(path, strict=False)
|
result = mimetypes.guess_type(path, strict=False)
|
||||||
|
if ms is not None:
|
||||||
|
ms.close()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
# Scan the source code in the given directory (and all subdirectories)
|
# Scan the source code in the given directory (and all subdirectories)
|
||||||
|
Loading…
Reference in New Issue
Block a user