Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce reliance on the mime database #21382

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HanabishiRecca
Copy link
Contributor

@HanabishiRecca HanabishiRecca commented Sep 23, 2024

This is a two part PR. See a discussion from #21363 (comment).

Move Path mime extension retrieval into a separate method

Reasons:

  • Most Path::extension() callers do not need that.
  • Mime database is unreliable and could be manipulated by the system environment.
  • Unnecessary overhead.

WebUI: Store common mime types inside the app

Makes WebUI usable if the mime database is absent or broken.

Related:

if (mimeType.isNull())
mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data).name();

const bool isTranslatable = !m_isAltUIUsed && mimeType.startsWith(u"text/"_s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it is acceptable change. mimeType.inherits(u"text/plain"_s) has a much larger reach.

As I said earlier I won't approve fighting with mime database usage as a goal. I would keep using QMimeType instead of type names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is no other way around it.
If you disapprove, close #21363 as wontfix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is no other way around it.

Just

keep using QMimeType instead of type names.

It shouldn't prevent you from hardcode some fileextension-to-mimetype mapping.

Copy link
Contributor Author

@HanabishiRecca HanabishiRecca Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this could be possible. As far as I understand,

keep using QMimeType instead of type names.

is mutually exclusive with

hardcode some fileextension-to-mimetype mapping

because QMimeType requires the database to work.

The class can't even be constructed from arbitrary data. The only way to create it is to query QMimeDatabase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this could be possible. As far as I understand,

keep using QMimeType instead of type names.

is mutually exclusive with

hardcode some fileextension-to-mimetype mapping

because QMimeType requires the database to work.

As I mentioned, I don't consider abandoning QMimeDatabase as a goal. It is enough to prevent the use of incorrect file type associations. To do this, we need to get associations for important files (such as html, js, css) not from the system mime database (where they can be corrupted), but hard-code them instead. We need QMimeDatabase::mimeTypeForName() to achieve it which I believe isn't affected by the issue we want to avoid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need QMimeDatabase::mimeTypeForName() to achieve it which I believe isn't affected by the issue we want to avoid.

It is affected. Everything in QMimeDatabase is affected. Because all types can be overridden in a user local database.

Copy link
Contributor Author

@HanabishiRecca HanabishiRecca Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the whole thing seems hardcoded. I don't see a way to forbid it loading external databases. That could have been a perfect simple solution in our case.

https://github.com/qt/qtbase/blob/8b3865e15120d1f85590cc6e1a5ca9fa41697705/src/corelib/mimetypes/qmimedatabase.cpp#L72-L171

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there is a dead end here? Should I close the PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expressed my opinion. We can wait for someone else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess nobody else wants to participate.

@glassez
Copy link
Member

glassez commented Sep 24, 2024

I continue to hold the opinion that the referenced Issues are not qBittorrent bugs, but problems on the user's side. I don't mind using some kind of workarounds to reduce the chances of their occurrence, but only without worsen the current functionality of qBittorrent. Using mime database is not a disadvantage in itself, IMO.

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Sep 24, 2024

but only without worsen the current functionality of qBittorrent.

Could you explain how exactly it worsen the functionality? I don't see any changes in behavior at all.

Using mime database is not a disadvantage in itself, IMO.

It is, IMO. I use a headless Qt build on a server, which doesn't depend on shared-mime-info by itself. So shared-mime-info is installed explicitly for WebUI to work. This change gets rid of the dependency and allows WebUI to operate without it.

But I understand that this is an uncommon scenario.

@glassez
Copy link
Member

glassez commented Sep 24, 2024

Using mime database is not a disadvantage in itself, IMO.

It is, IMO. I use a headless Qt build on a server, which doesn't depend on shared-mime-info by itself. So shared-mime-info is installed explicitly for WebUI to work. This change gets rid of the dependency and allows WebUI to operate without it.

shared-mime-info isn't required according to Qt documentation:

The MIME type database is provided by the freedesktop.org shared-mime-info project. If the MIME type database cannot be found on the system, as is the case on most Windows, macOS, and iOS systems, Qt will use its own copy of it.

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Sep 24, 2024

shared-mime-info isn't required according to Qt documentation:

Hmm, indeed. It works without shared-mime-info now. 🤔
Ok, I have less concerns now.

I had the described WebUI problem in the past though. And installing shared-mime-info is what fixed it. Don't remember when exactly, but maybe it was in Qt 5 era. I simply never checked it again since then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing WEB UI only downloads an html template but does not display it
3 participants