Commit d4467a99 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Fix loading some zip files

In which QMimeType database says they are actually php files because
mimes are hard. So if we get no offers for the mime type based
on the contents try again with the extension one

BUGS: 445533
parent 38a1276f
Pipeline #102938 passed with stage
in 4 minutes and 1 second
...@@ -35,14 +35,20 @@ Archive *Archive::create(const QString &fileName, const QString &fixedMimeType, ...@@ -35,14 +35,20 @@ Archive *Archive::create(const QString &fileName, const QString &fixedMimeType,
PluginManager pluginManager; PluginManager pluginManager;
const QMimeType mimeType = fixedMimeType.isEmpty() ? determineMimeType(fileName) : QMimeDatabase().mimeTypeForName(fixedMimeType); const QMimeType mimeType = fixedMimeType.isEmpty() ? determineMimeType(fileName) : QMimeDatabase().mimeTypeForName(fixedMimeType);
const QVector<Plugin*> offers = pluginManager.preferredPluginsFor(mimeType); QVector<Plugin*> offers = pluginManager.preferredPluginsFor(mimeType);
if (offers.isEmpty()) { if (offers.isEmpty()) {
qCCritical(ARK) << "Could not find a plugin to handle" << fileName; if (fixedMimeType.isEmpty()) {
return new Archive(NoPlugin, parent); const QMimeType extensionMimeType = determineMimeType(fileName, PreferExtensionMime);
offers = pluginManager.preferredPluginsFor(extensionMimeType);
}
if (offers.isEmpty()) {
qCCritical(ARK) << "Could not find a plugin to handle" << fileName;
return new Archive(NoPlugin, parent);
}
} }
Archive *archive = nullptr; Archive *archive = nullptr;
for (Plugin *plugin : offers) { for (Plugin *plugin : std::as_const(offers)) {
archive = create(fileName, plugin, parent); archive = create(fileName, plugin, parent);
// Use the first valid plugin, according to the priority sorting. // Use the first valid plugin, according to the priority sorting.
if (archive->isValid()) { if (archive->isValid()) {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace Kerfuffle namespace Kerfuffle
{ {
QMimeType determineMimeType(const QString& filename) QMimeType determineMimeType(const QString& filename, MimePreference mp)
{ {
QMimeDatabase db; QMimeDatabase db;
...@@ -111,7 +111,7 @@ QMimeType determineMimeType(const QString& filename) ...@@ -111,7 +111,7 @@ QMimeType determineMimeType(const QString& filename)
<< "). Using content-based mimetype."; << "). Using content-based mimetype.";
} }
return mimeFromContent; return mp == PreferExtensionMime ? mimeFromExtension : mimeFromContent;
} }
} // namespace Kerfuffle } // namespace Kerfuffle
...@@ -13,11 +13,18 @@ ...@@ -13,11 +13,18 @@
namespace Kerfuffle namespace Kerfuffle
{ {
enum MimePreference {
PreferContentsMime,
PreferExtensionMime
};
/** /**
* @param filename Absolute path of a file. * @param filename Absolute path of a file.
* @param mp Whether to prefer extension or contents mime when they disagree.
* @return The mimetype of the given file. * @return The mimetype of the given file.
*/ */
KERFUFFLE_EXPORT QMimeType determineMimeType(const QString& filename); KERFUFFLE_EXPORT QMimeType determineMimeType(const QString& filename, MimePreference mp = PreferContentsMime);
} }
#endif // MIMETYPES_H #endif // MIMETYPES_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment