Commit 15030360 authored by Stefan Brüns's avatar Stefan Brüns
Browse files

Check if file exists and is readable early

Instead of returning an unspecific error later, when ThumbCreator::create
fails due to a nonexisting or unreadable file, immediately error out.
parent 0e219fd8
......@@ -163,29 +163,33 @@ void ThumbnailProtocol::get(const QUrl &url)
const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings");
m_enabledPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins());
}
Q_ASSERT(url.scheme() == "thumbnail");
QFileInfo info(url.path());
Q_ASSERT(info.isAbsolute());
if (!info.exists()) {
// The file does not exist
error(KIO::ERR_DOES_NOT_EXIST, url.path());
return;
} else if (!info.isReadable()) {
// The file is not readable!
error(KIO::ERR_CANNOT_READ, url.path());
return;
}
//qDebug() << "Wanting MIME Type:" << m_mimeType;
#ifdef THUMBNAIL_HACK
// ### HACK
bool direct=false;
if (m_mimeType.isEmpty()) {
QFileInfo info(url.path());
//qDebug() << "PATH: " << url.path() << "isDir:" << info.isDir();
if (!info.exists()) {
// The file does not exist
error(KIO::ERR_DOES_NOT_EXIST,url.path());
return;
} else if (!info.isReadable()) {
// The file is not readable!
error(KIO::ERR_CANNOT_READ,url.path());
return;
}
if (info.isDir()) {
m_mimeType = "inode/directory";
} else {
const QMimeDatabase db;
m_mimeType = db.mimeTypeForUrl(QUrl(info.filePath())).name();
m_mimeType = db.mimeTypeForFile(info).name();
}
//qDebug() << "Guessing MIME Type:" << m_mimeType;
......
Markdown is supported
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