[filetransferjob] Simplify error handling

QNetworkReply::finished is also emitted in the error case, so by also connecting to errorOccured we emitResult twice
This commit is contained in:
Nicolas Fella 2024-04-16 16:37:54 +02:00
parent 52e64e32b1
commit 8c62a108d6
2 changed files with 14 additions and 21 deletions

View file

@ -94,35 +94,29 @@ void FileTransferJob::startTransfer()
m_written = bytesSent; m_written = bytesSent;
}); });
connect(m_reply, &QNetworkReply::errorOccurred, this, &FileTransferJob::transferFailed);
connect(m_reply, &QNetworkReply::finished, this, &FileTransferJob::transferFinished); connect(m_reply, &QNetworkReply::finished, this, &FileTransferJob::transferFinished);
} }
void FileTransferJob::transferFailed(QNetworkReply::NetworkError error)
{
qCDebug(KDECONNECT_CORE) << "Couldn't transfer the file successfully" << error << m_reply->errorString();
setError(error);
setErrorText(i18n("Received incomplete file: %1", m_reply->errorString()));
emitResult();
m_reply->close();
}
void FileTransferJob::transferFinished() void FileTransferJob::transferFinished()
{ {
// TODO: MD5-check the file if (m_reply->error()) {
if (m_size == m_written) { qCDebug(KDECONNECT_CORE) << "Couldn't transfer the file successfully" << m_reply->error() << m_reply->errorString();
qCDebug(KDECONNECT_CORE) << "Finished transfer" << m_destination; setError(m_reply->error());
emitResult(); setErrorText(m_reply->errorString());
} else { } else {
qCDebug(KDECONNECT_CORE) << "Received incomplete file (" << m_written << "/" << m_size << "bytes ), deleting"; // TODO: MD5-check the file
if (m_size == m_written) {
qCDebug(KDECONNECT_CORE) << "Finished transfer" << m_destination;
} else {
qCDebug(KDECONNECT_CORE) << "Received incomplete file (" << m_written << "/" << m_size << "bytes ), deleting";
deleteDestinationFile(); deleteDestinationFile();
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() void FileTransferJob::deleteDestinationFile()

View file

@ -62,7 +62,6 @@ protected:
private: private:
void startTransfer(); void startTransfer();
void transferFailed(QNetworkReply::NetworkError error);
void transferFinished(); void transferFinished();
void deleteDestinationFile(); void deleteDestinationFile();