From 463f04feda69bdf904b6acaf4d0d79978d5896c4 Mon Sep 17 00:00:00 2001 From: "huheng@kylinos.cn" Date: Tue, 4 Apr 2023 10:26:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(=E6=96=87=E4=BB=B6=E4=BC=A0?= =?UTF-8?q?=E8=BE=93):=20=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filetransfer/ftpclient/ftpmanager.cpp | 28 +++++++++++++++------------ filetransfer/ftpclient/ftpmanager.h | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/filetransfer/ftpclient/ftpmanager.cpp b/filetransfer/ftpclient/ftpmanager.cpp index 05c2484..8013c6b 100644 --- a/filetransfer/ftpclient/ftpmanager.cpp +++ b/filetransfer/ftpclient/ftpmanager.cpp @@ -274,18 +274,23 @@ void FtpManager::ftpCommandFinished(int commandId, bool error) } if (m_ftp->currentCommand() == QFtp::Put) { - QString fileName = m_uploadFiles.take(commandId); - if (fileName.isEmpty()) { + QFile *file = m_uploadFiles.take(commandId); + if (file == nullptr) { return; } if (error) { + QString fileName = file->fileName(); qWarning() << "CommandFinished: Cancle the file success: " << fileName; Q_EMIT sigDownFileFail(fileName.mid(fileName.lastIndexOf("/") + 1, fileName.size())); abort(); } else { + QString fileName = file->fileName(); qInfo() << "CommandFinished: Upload the file success: " << fileName; } // 将该文件从上传文件中删除 + file->close(); + delete file; + file = nullptr; m_uploadFiles.remove(commandId); return; } @@ -528,6 +533,7 @@ void FtpManager::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes) m_isFree = true; // this->cdToDir(m_downBeforePath); } + Q_EMIT sigUpdateTransferProgress(m_readProgress, m_updateAllFileSize); } } @@ -674,13 +680,9 @@ void FtpManager::upload(const QStringList &fileList, QString uploadPath) file = nullptr; continue; } - QByteArray data = file->readAll(); int id = 0; - id = m_ftp->put(data, uploadPath + "/" + fileName); - m_uploadFiles.insert(id, uploadPath + "/" + fileName); - file->close(); - delete file; - file = nullptr; + id = m_ftp->put(file, uploadPath + "/" + fileName); + m_uploadFiles.insert(id, file); } } @@ -766,13 +768,13 @@ void FtpManager::clearErrorFiles() } } // 清理未完成上传的文件 - QMap::iterator uploadIt = m_uploadFiles.begin(); + QMap::iterator uploadIt = m_uploadFiles.begin(); while (uploadIt != m_uploadFiles.end()) { - if (uploadIt.value().isEmpty()) { + if (uploadIt.value() == nullptr) { uploadIt++; continue; } else { - QString fileName = uploadIt.value(); + QString fileName = uploadIt.value()->fileName(); QString filePath = fileName.mid(0, fileName.lastIndexOf('/') + 1); fileName = fileName.mid(fileName.lastIndexOf('/') + 1, fileName.size()); if (filePath != m_currentPath) { @@ -782,7 +784,9 @@ void FtpManager::clearErrorFiles() } else { m_ftp->remove(fileName); } - uploadIt.value().clear(); + uploadIt.value()->close(); + uploadIt.value()->deleteLater(); + uploadIt.value() = nullptr; } } } diff --git a/filetransfer/ftpclient/ftpmanager.h b/filetransfer/ftpclient/ftpmanager.h index d3f082e..67110e3 100644 --- a/filetransfer/ftpclient/ftpmanager.h +++ b/filetransfer/ftpclient/ftpmanager.h @@ -93,7 +93,7 @@ private: QString m_downBeforePath = ""; // 进行下载之前的路径 QMap m_currentAllFiles; // 当前路径下文件列表 QMap m_downFiles; // 所有下载文件 - QMap m_uploadFiles; // 所有上传文件 + QMap m_uploadFiles; // 所有上传文件 QMap m_taskLocalMap; // 用于记录上传文件夹中文件的本地路径 QMap m_taskPathMap; // 用于记录每一次任务的上传|下载路径 QMap m_taskDownloadMap; // 记录当前下载信息