fix: handle non-existent file paths in tab management#470
Conversation
1. Added Utils::getFilePath() that returns canonicalFilePath() for existing files and falls back to absoluteFilePath() for non-existent files to support new file creation. 2. Updated StartManager to use Utils::getFilePath() instead of directly using canonicalFilePath() when opening files in windows/tabs. 3. Modified EditWrapper::handleFileLoadFinished to suppress error notifications for non-existent files (new file scenario). 4. Fixed issue where tabs for new files could not be properly displayed or closed due to empty canonical paths. Log: When creating new files, the editor no longer shows spurious error popups or fails to manage tabs correctly. Influence: 1. Test creating new files from various entry points (e.g., double-click in file manager, command line, DBus). 2. Verify that existing files still open correctly with symlinks resolved. 3. Verify that tabs for new files display correctly and can be closed without errors. 4. Verify that opening non-existent files via recent files list does not cause error dialogs. fix: 处理标签页管理中不存在的文件路径 1. 新增 Utils::getFilePath() 方法,对已存在文件返回规范路径,对不存在的 文件返回绝对路径,以支持新建文件场景。 2. 更新 StartManager 中使用 Utils::getFilePath() 替代直接使用 canonicalFilePath() 打开文件。 3. 修改 EditWrapper::handleFileLoadFinished,对于不存在的文件静默处理 (新建文件场景),不显示错误提示。 4. 修复新建文件时标签页无法正确显示或关闭的问题。 Log: 新建文件时,编辑器不再显示错误弹窗,标签页管理恢复正常。 Influence: 1. 测试从不同入口新建文件(如双击文件管理器、命令行、DBus接口)。 2. 验证已存在文件仍能正确打开,且符号链接解析正常。 3. 验证新建文件的标签页显示正确且可以正常关闭。 4. 验证从最近文件列表打开不存在的文件时不会弹出错误对话框。 BUG: https://pms.uniontech.com/bug-view-336931.html
deepin pr auto review你好!我是CodeGeeX,很高兴为你审查这段代码。 这次代码变更的核心目的是解决新建文件(不存在的文件)在使用 整体逻辑清晰,改进合理。但为了代码的健壮性、安全性和可维护性,我为你提供以下详细的审查意见: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议针对上述安全性和逻辑问题,建议对 QString Utils::getFilePath(const QString &filePath)
{
QFileInfo info(filePath);
QString canonicalPath = info.canonicalFilePath();
// canonicalFilePath() returns empty string for non-existent files
// Use absoluteFilePath() as fallback to support creating new files
if (canonicalPath.isEmpty()) {
// 使用 QDir::cleanPath 清理路径中可能存在的 "." 或 "..",防止路径遍历风险
// 并确保即使是不存在的文件,返回的也是格式规范的绝对路径
return QDir::cleanPath(info.absoluteFilePath());
}
return canonicalPath;
}同时,建议完善 /**
* @brief getFilePath 获取文件路径
* @param filePath 原始文件路径
* @return 文件路径
* @note 优先使用 canonicalFilePath()(解析符号链接并消除 '.' 或 '..'),
* 当文件不存在时返回空字符串,此时使用 QDir::cleanPath(absoluteFilePath())
* 作为后备方案,确保即使是新建文件,标签页也能正确显示和关闭。
* 【注意】对于不存在的文件,此方法无法解析符号链接。当该文件后续被创建时,
* 调用方需注意更新路径,以免同一文件因路径形态不同而导致标签页重复。
*/
static QString getFilePath(const QString &filePath);总结本次代码修改方向正确,有效地修复了新建文件场景下的路径获取和错误提示问题。主要改进点在于防范路径遍历风险(使用 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Kakueeen, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
existing files and falls back to absoluteFilePath() for non-existent
files to support new file creation.
using canonicalFilePath() when opening files in windows/tabs.
notifications for non-existent files (new file scenario).
or closed due to empty canonical paths.
Log: When creating new files, the editor no longer shows spurious error
popups or fails to manage tabs correctly.
Influence:
in file manager, command line, DBus).
resolved.
without errors.
cause error dialogs.
fix: 处理标签页管理中不存在的文件路径
文件返回绝对路径,以支持新建文件场景。
canonicalFilePath() 打开文件。
(新建文件场景),不显示错误提示。
Log: 新建文件时,编辑器不再显示错误弹窗,标签页管理恢复正常。
Influence:
BUG: https://pms.uniontech.com/bug-view-336931.html