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

View file

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