Skip to content

Commit 930da60

Browse files
pppanghu77deepin-bot[bot]
authored andcommitted
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 930da60

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#include "settinghepler.h"
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "settinghepler.h"
26

37
#include "common/log.h"
48

@@ -71,7 +75,7 @@ bool SettingHelper::handleDataConfiguration(const QString &path)
7175

7276
QDir pdir(path);
7377
QString filepath = pdir.absolutePath() + "/";
74-
QJsonObject jsonObj = ParseJson(filepath + "transfer.json");
78+
QJsonObject jsonObj = ParseJson(pdir.filePath("transfer.json"));
7579
if (jsonObj.isEmpty()) {
7680
addTaskcounter(-1);
7781
WLOG << "transfer.json is invaild";
@@ -100,8 +104,10 @@ bool SettingHelper::handleDataConfiguration(const QString &path)
100104
}
101105
}
102106
addTaskcounter(-1);
103-
//remove dir
104-
pdir.removeRecursively();
107+
//remove transfer.json
108+
const QString jsonFile = pdir.filePath("transfer.json");
109+
if (!QFile::remove(jsonFile))
110+
WLOG << "Failed to remove transfer.json: " << jsonFile.toStdString();
105111
return true;
106112
}
107113

@@ -309,8 +315,11 @@ bool SettingHelper::setFile(QJsonObject jsonObj, QString filepath)
309315
const QJsonArray &userFileArray = userFileValue.toArray();
310316
for (const auto &value : userFileArray) {
311317
QString filename = value.toString();
318+
319+
// 只保留文件名部分,兼容相对路径和绝对路径格式
320+
QString file = filepath + QFileInfo(filename).fileName();
321+
312322
QString targetFile = QDir::homePath() + "/" + filename;
313-
QString file = filepath + filename.mid(filename.indexOf('/') + 1);
314323
QFileInfo info = QFileInfo(targetFile);
315324
auto dir = info.dir();
316325
if (!dir.exists())

0 commit comments

Comments
 (0)