chiark
/
gitweb
/
~ianmdlvl
/
fdroidserver.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
576135f
)
Fix multiple errors in get_mime_type
author
Ciaran Gultnieks
<ciaran@ciarang.com>
Thu, 13 Aug 2015 17:16:28 +0000
(19:16 +0200)
committer
Ciaran Gultnieks
<ciaran@ciarang.com>
Thu, 13 Aug 2015 17:16:28 +0000
(19:16 +0200)
Closes #111
fdroidserver/common.py
patch
|
blob
|
history
diff --git
a/fdroidserver/common.py
b/fdroidserver/common.py
index 7b2aa0875156074e4fec3cd9477e77324787f9de..e775e846bea05bef1a4e4b24d53c37517c2fa6b7 100644
(file)
--- a/
fdroidserver/common.py
+++ b/
fdroidserver/common.py
@@
-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:
import magic
try:
import magic
- ms = None
try:
ms = magic.open(magic.MIME_TYPE)
ms.load()
try:
ms = magic.open(magic.MIME_TYPE)
ms.load()
- re
turn
magic.from_file(path, mime=True)
+ re
sult =
magic.from_file(path, mime=True)
except AttributeError:
except AttributeError:
- return ms.file(path)
- if ms is not None:
- ms.close()
+ result = ms.file(path)
except UnicodeError:
logging.warn('Found malformed magic number at %s' % path)
except UnicodeError:
logging.warn('Found malformed magic number at %s' % path)
+ result = None
except ImportError:
import mimetypes
mimetypes.init()
except ImportError:
import mimetypes
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)