Delete partially downloaded file when transfer is canceled locally

This commit is contained in:
Erik Duisters 2019-05-02 18:49:50 +02:00
parent 6c6cd751ba
commit 6fb67d0261
2 changed files with 13 additions and 4 deletions

View file

@ -130,16 +130,21 @@ void FileTransferJob::transferFinished()
} else {
qCDebug(KDECONNECT_CORE) << "Received incomplete file ("<< m_written << "/" << m_size << "bytes ), deleting";
if (m_destination.isLocalFile() && QFile::exists(m_destination.toLocalFile())) {
QFile::remove(m_destination.toLocalFile());
}
deleteDestinationFile();
setError(3);
setErrorText(i18n("Received incomplete file from: %1", m_from));
emitResult();
}
}
void FileTransferJob::deleteDestinationFile()
{
if (m_destination.isLocalFile() && QFile::exists(m_destination.toLocalFile())) {
QFile::remove(m_destination.toLocalFile());
}
}
bool FileTransferJob::doKill()
{
if (m_reply) {
@ -148,5 +153,8 @@ bool FileTransferJob::doKill()
if (m_origin) {
m_origin->close();
}
deleteDestinationFile();
return true;
}

View file

@ -64,6 +64,7 @@ private:
void startTransfer();
void transferFailed(QNetworkReply::NetworkError error);
void transferFinished();
void deleteDestinationFile();
QSharedPointer<QIODevice> m_origin;
QNetworkReply* m_reply;