Skip to content

Commit 2334e9f

Browse files
committed
fix(data-transfer): improve file path handling in setting helper
- Extract only the filename part from the full path to support both relative and absolute path formats - Use QFileInfo to properly handle path separators across different platforms - Replace complex string manipulation with more robust file name extraction logic
1 parent 7ea784a commit 2334e9f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/lib/data-transfer/core/utils/settinghepler.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bool SettingHelper::handleDataConfiguration(const QString &path)
7171

7272
QDir pdir(path);
7373
QString filepath = pdir.absolutePath() + "/";
74-
QJsonObject jsonObj = ParseJson(filepath + "transfer.json");
74+
QJsonObject jsonObj = ParseJson(QDir(filepath).filePath("transfer.json"));
7575
if (jsonObj.isEmpty()) {
7676
addTaskcounter(-1);
7777
WLOG << "transfer.json is invaild";
@@ -100,8 +100,10 @@ bool SettingHelper::handleDataConfiguration(const QString &path)
100100
}
101101
}
102102
addTaskcounter(-1);
103-
//remove dir
104-
pdir.removeRecursively();
103+
//remove transfer.json
104+
const QString jsonFile = QDir(filepath).filePath("transfer.json");
105+
if (!QFile::remove(jsonFile))
106+
WLOG << "Failed to remove transfer.json: " << jsonFile.toStdString();
105107
return true;
106108
}
107109

@@ -309,8 +311,11 @@ bool SettingHelper::setFile(QJsonObject jsonObj, QString filepath)
309311
const QJsonArray &userFileArray = userFileValue.toArray();
310312
for (const auto &value : userFileArray) {
311313
QString filename = value.toString();
314+
315+
// 只保留文件名部分,兼容相对路径和绝对路径格式
316+
QString file = filepath + QFileInfo(filename).fileName();
317+
312318
QString targetFile = QDir::homePath() + "/" + filename;
313-
QString file = filepath + filename.mid(filename.indexOf('/') + 1);
314319
QFileInfo info = QFileInfo(targetFile);
315320
auto dir = info.dir();
316321
if (!dir.exists())

0 commit comments

Comments
 (0)