Skip to content

Commit

Permalink
[libcontentaction] Expose an error when opening an empty file. Contri…
Browse files Browse the repository at this point in the history
…butes to JB#41147
  • Loading branch information
rainemak committed Jun 12, 2018
1 parent 28451ac commit c31e6c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion declarative/declarativecontentaction.cpp
Expand Up @@ -50,13 +50,26 @@ bool DeclarativeContentAction::trigger(const QUrl &url)
}

if (url.isLocalFile()) {
if (!QFile::exists(url.toLocalFile())) {
QString localFile = url.toLocalFile();
if (!QFile::exists(localFile)) {
qWarning() << Q_FUNC_INFO << "File doesn't exist!";
m_error = FileDoesNotExist;
emit errorChanged();
return false;
}

QFile file(localFile);
if (file.open(QIODevice::ReadOnly) && file.size() == 0) {
m_error = FileIsEmpty;
emit errorChanged();
file.close();
return false;
}

if (file.openMode() != QIODevice::NotOpen) {
file.close();
}

ContentAction::Action action = ContentAction::Action::defaultActionForFile(url);
if (!action.isValid()) {
m_error = FileTypeNotSupported;
Expand Down
1 change: 1 addition & 0 deletions declarative/declarativecontentaction.h
Expand Up @@ -37,6 +37,7 @@ class DeclarativeContentAction: public QObject
NoError,
FileTypeNotSupported,
FileDoesNotExist,
FileIsEmpty,
UrlSchemeNotSupported,
InvalidUrl
};
Expand Down

0 comments on commit c31e6c9

Please sign in to comment.