[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,26 +94,19 @@ 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()
{ {
if (m_reply->error()) {
qCDebug(KDECONNECT_CORE) << "Couldn't transfer the file successfully" << m_reply->error() << m_reply->errorString();
setError(m_reply->error());
setErrorText(m_reply->errorString());
} else {
// TODO: MD5-check the file // TODO: MD5-check the file
if (m_size == m_written) { if (m_size == m_written) {
qCDebug(KDECONNECT_CORE) << "Finished transfer" << m_destination; qCDebug(KDECONNECT_CORE) << "Finished transfer" << m_destination;
emitResult();
} 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";
@ -121,8 +114,9 @@ void FileTransferJob::transferFinished()
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();