diff options
author | kh1 <karsten.heimrich@digia.com> | 2014-05-22 11:37:59 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2014-05-22 12:36:42 +0200 |
commit | 93408c8fb69175543390a5c9f98615216e6eb8fc (patch) | |
tree | ecfc99bbdc41ed9885bbb24137c46f09209230c7 /src/libs/installer/downloadfiletask.cpp | |
parent | fa0c10dc1d953880ff24459792796e69500acbd5 (diff) |
Check if the file we are writing to is a file.
Remove superfluous remove, since if the file exists but we
can't open it it might belong to someone else, so keep it...
Change-Id: Ic541fe134dad76983088d4b3d243d15e78f9fed4
Reviewed-by: Niels Weber <niels.weber@digia.com>
Diffstat (limited to 'src/libs/installer/downloadfiletask.cpp')
-rw-r--r-- | src/libs/installer/downloadfiletask.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libs/installer/downloadfiletask.cpp b/src/libs/installer/downloadfiletask.cpp index 8d15a835d..1cb64251a 100644 --- a/src/libs/installer/downloadfiletask.cpp +++ b/src/libs/installer/downloadfiletask.cpp @@ -45,6 +45,7 @@ #include <QEventLoop> #include <QFile> +#include <QFileInfo> #include <QNetworkProxyFactory> #include <QSslError> #include <QTemporaryFile> @@ -307,8 +308,14 @@ QNetworkReply *Downloader::startDownload(const FileTaskItem &item) } else { file.reset(new QFile(target)); } + + if (file->exists() && (!QFileInfo(file->fileName()).isFile())) { + m_futureInterface->reportException(FileTaskException(QString::fromLatin1("Target file " + "'%1' already exists but is not a file.").arg(file->fileName()))); + return 0; + } + if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate)) { - file->remove(); m_futureInterface->reportException(FileTaskException(QString::fromLatin1("Could not open " "target '%1' for write. Error: %2.").arg(file->fileName(), file->errorString()))); return 0; |