Merge branch 'drop_imghdr' into 'master'

scanner: replace deprecated imghdr with libmagic/puremagic

See merge request fdroid/fdroidserver!1543
This commit is contained in:
Jochen Sprickerhof 2024-11-25 13:57:06 +00:00
commit cd29dd84d2
2 changed files with 12 additions and 3 deletions

View file

@ -16,7 +16,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import imghdr
import itertools
import json
import logging
@ -35,6 +34,11 @@ from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Union
try:
import magic
except ImportError:
import puremagic as magic
if sys.version_info >= (3, 11):
import tomllib
else:
@ -895,8 +899,12 @@ def scan_source(build_dir, build=metadata.Build(), json_per_build=None):
]
def is_image_file(path):
if imghdr.what(path) is not None:
try:
mimetype = magic.from_file(path, mime=True)
if mimetype and mimetype.startswith('image/'):
return True
except Exception as e:
logging.info(e)
def safe_path(path_in_build_dir):
for sp in safe_paths:

View file

@ -100,6 +100,7 @@ setup(
'paramiko',
'Pillow',
'apache-libcloud >= 0.14.1',
'puremagic',
'python-vagrant',
'PyYAML',
'qrcode',