fix: remote judge not exist file bug.

This commit is contained in:
2025-06-20 13:03:27 +08:00
parent ce3d3a1866
commit 0334b22ad6
2 changed files with 28 additions and 21 deletions

View File

@@ -18,7 +18,13 @@ FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
void FileTrans::ReqSendFile(const TransTask& task) void FileTrans::ReqSendFile(const TransTask& task)
{ {
// TODO: check if running... // TODO: check if running...
if (sendTask_->file.isOpen()) {
qWarning() << QString(tr("file [%1] is running.")).arg(sendTask_->file.fileName());
while (sendTask_->file.isOpen()) {
QThread::msleep(1);
}
qWarning() << QString(tr("file [%1] is exit running.")).arg(sendTask_->file.fileName());
}
// start // start
InfoMsg info; InfoMsg info;
info.toPath = task.remotePath; info.toPath = task.remotePath;
@@ -85,20 +91,26 @@ void FileTrans::ReqDownFile(const TransTask& task)
qint32 FileTrans::GetSendProgress() qint32 FileTrans::GetSendProgress()
{ {
if (sendTask_->state == TaskState::STATE_FINISH) { if (sendTask_->state == TaskState::STATE_FINISH) {
downTask_->state == TaskState::STATE_NONE; sendTask_->state = TaskState::STATE_NONE;
return 100; return 100;
} }
if (sendTask_->state != TaskState::STATE_RUNNING) { if (sendTask_->state != TaskState::STATE_RUNNING) {
return -1; return -1;
} }
// wait file state ok.
double per = (sendTask_->tranSize * 100.0) / sendTask_->totalSize; double per = (sendTask_->tranSize * 100.0) / sendTask_->totalSize;
return per; qint32 rt = static_cast<qint32>(per);
if (rt >= 100) {
return 99;
}
return rt;
} }
qint32 FileTrans::GetDownProgress() qint32 FileTrans::GetDownProgress()
{ {
if (downTask_->state == TaskState::STATE_FINISH) { if (downTask_->state == TaskState::STATE_FINISH) {
downTask_->state == TaskState::STATE_NONE; downTask_->state = TaskState::STATE_NONE;
return 100; return 100;
} }
if (downTask_->state != TaskState::STATE_RUNNING) { if (downTask_->state != TaskState::STATE_RUNNING) {
@@ -107,8 +119,13 @@ qint32 FileTrans::GetDownProgress()
if (downTask_->totalSize == 0) { if (downTask_->totalSize == 0) {
return 0; return 0;
} }
// wait file state ok.
double per = (downTask_->tranSize * 100.0) / downTask_->totalSize; double per = (downTask_->tranSize * 100.0) / downTask_->totalSize;
return per; qint32 rt = static_cast<qint32>(per);
if (rt >= 100) {
return 99;
}
return rt;
} }
void FileTrans::RegisterSignal() void FileTrans::RegisterSignal()
@@ -357,6 +374,7 @@ void SendThread::run()
auto f = cliCore_->GetBuffer(info, FBT_CLI_TRANS_DONE, task_->task.remoteId); auto f = cliCore_->GetBuffer(info, FBT_CLI_TRANS_DONE, task_->task.remoteId);
ClientCore::asyncInvoke(cliCore_, [this, f]() { return cliCore_->Send(f); }); ClientCore::asyncInvoke(cliCore_, [this, f]() { return cliCore_->Send(f); });
task_->file.close(); task_->file.close();
task_->state = TaskState::STATE_FINISH;
} }
void SendThread::setTask(const QSharedPointer<DoTransTask>& task) void SendThread::setTask(const QSharedPointer<DoTransTask>& task)

View File

@@ -80,29 +80,18 @@ void Util::InitLogger(const QString& logPath, const QString& mark)
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
// do not check exit
QString Util::Get2FilePath(const QString& file, const QString& directory) QString Util::Get2FilePath(const QString& file, const QString& directory)
{ {
if (file.isEmpty() || directory.isEmpty()) { if (file.isEmpty() || directory.isEmpty()) {
return QString(); return QString();
} }
QFileInfo fileInfo(file); QString fileName = QFileInfo(file).fileName();
QDir dir(directory); QString cleanDir = QDir::cleanPath(directory);
QString fullPath = QDir(cleanDir).filePath(fileName);
if (!fileInfo.isFile()) { return QDir::cleanPath(fullPath);
qWarning() << "Path A is not a file:" << file;
return QString();
}
if (!dir.exists()) {
qWarning() << "Path B is not a valid directory:" << directory;
return QString();
}
QString fileName = fileInfo.fileName();
QString cleanPathB = QDir::cleanPath(directory);
QString newPath = cleanPathB + QDir::separator() + fileName;
newPath = QDir::cleanPath(newPath);
return newPath;
} }
void Util::ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg) void Util::ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg)