kdecore: remove redundant KMimeTypeRepository::findFromContent() argument

always an empty QByteArray object is passed

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-11 16:21:21 +02:00
parent 860137350d
commit 0f329f3f5a
3 changed files with 11 additions and 18 deletions

View file

@ -200,9 +200,8 @@ KMimeType::Ptr KMimeType::findByUrlHelper( const KUrl& _url, mode_t mode,
// Try the magic matches (if we can read the data)
if ( device ) {
QByteArray cache;
int magicAccuracy;
KMimeType::Ptr mime = KMimeTypeRepository::self()->findFromContent(device, &magicAccuracy, cache);
KMimeType::Ptr mime = KMimeTypeRepository::self()->findFromContent(device, &magicAccuracy);
// mime can't be 0, except in case of install problems.
// However we get magicAccuracy==0 for octet-stream, i.e. no magic match found.
//kDebug(servicesDebugArea()) << "findFromContent said" << (mime?mime->name():QString()) << "with accuracy" << magicAccuracy;
@ -328,14 +327,12 @@ KMimeType::Ptr KMimeType::findByContent( const QByteArray &data, int *accuracy )
{
QBuffer buffer(const_cast<QByteArray *>(&data));
buffer.open(QIODevice::ReadOnly);
QByteArray cache;
return KMimeTypeRepository::self()->findFromContent(&buffer, accuracy, cache);
return KMimeTypeRepository::self()->findFromContent(&buffer, accuracy);
}
KMimeType::Ptr KMimeType::findByContent( QIODevice* device, int* accuracy )
{
QByteArray cache;
return KMimeTypeRepository::self()->findFromContent(device, accuracy, cache);
return KMimeTypeRepository::self()->findFromContent(device, accuracy);
}
KMimeType::Ptr KMimeType::findByFileContent( const QString &fileName, int *accuracy )
@ -356,8 +353,7 @@ KMimeType::Ptr KMimeType::findByFileContent( const QString &fileName, int *accur
return KMimeType::defaultMimeTypePtr();
}
QByteArray cache;
return KMimeTypeRepository::self()->findFromContent(&device, accuracy, cache);
return KMimeTypeRepository::self()->findFromContent(&device, accuracy);
}
bool KMimeType::isBinaryData( const QString &fileName )

View file

@ -228,7 +228,7 @@ QStringList KMimeTypeRepository::findFromFileName(const QString &fileName, QStri
return matchingMimeTypes;
}
KMimeType::Ptr KMimeTypeRepository::findFromContent(QIODevice* device, int* accuracy, QByteArray& beginning)
KMimeType::Ptr KMimeTypeRepository::findFromContent(QIODevice* device, int* accuracy)
{
Q_ASSERT(device->isOpen());
const qint64 deviceSize = device->size();
@ -237,13 +237,11 @@ KMimeType::Ptr KMimeTypeRepository::findFromContent(QIODevice* device, int* accu
*accuracy = 100;
return findMimeTypeByName(QLatin1String("application/x-zerosize"));
}
if (beginning.isEmpty()) {
// check if we can really read the data; also provide enough data for most rules
const qint64 dataNeeded = qMin(deviceSize, (qint64) 16384);
beginning.resize(dataNeeded);
if (!device->seek(0) || device->read(beginning.data(), dataNeeded) == -1) {
return defaultMimeTypePtr(); // don't bother detecting unreadable file
}
// check if we can really read the data; also provide enough data for most rules
const qint64 dataNeeded = qMin(deviceSize, (qint64) 16384);
QByteArray beginning(dataNeeded, '\0');
if (!device->seek(0) || device->read(beginning.data(), dataNeeded) == -1) {
return defaultMimeTypePtr(); // don't bother detecting unreadable file
}
parseMagic();

View file

@ -104,11 +104,10 @@ private: // only for KMimeType and unittests
* Find a mimetype from the content of a file or buffer
* @param device the file or buffer. Must be open.
* @param accuracy returns the priority of the rule that matched
* @param beginning will contain the first N bytes of the device; used as cache to avoid repeated seeks
*
* This is internal API, use KMimeType::findByUrl instead.
*/
KMimeType::Ptr findFromContent(QIODevice* device, int* accuracy, QByteArray& beginning);
KMimeType::Ptr findFromContent(QIODevice* device, int* accuracy);
/**
* @return true if at least one mimetype is present